Add <NonSerialized()> attribute to implicitly created xxxEvent private fields??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Samuel R. Neff

    Add <NonSerialized()> attribute to implicitly created xxxEvent private fields??


    Is there a way to add the NonSerialized attribute to the "Event"
    fields that the VB.NET compiler creates when you declare an event?

    I have a class that we use with binary serialization and we just added
    two events so now old files won't deserialize to the new class. It
    says it was expecting 2 more fields, obviously corresponding to the
    two private fields created for the events.

    I tried adding the fields explicitly with the NonSerialized attribute
    but then I get a compiler error about the names conflicting.

    Thanks,

    Sam

  • Peter Huang [MSFT]

    #2
    RE: Add &lt;NonSerializ ed()&gt; attribute to implicitly created xxxEvent private fields??

    Hi

    Based on my understanding, you wants to mark a event in VB.NET as
    NonSerialized.
    In C# 1.1 we have an attribute [field:NonSerial ized].
    Unfortunately this is not supported in VB.NET on .net framework 1.1 and it
    will be added in vb.net 2005.
    Here is a link for your reference.

    ..NET 2.0 solution to serialization of objects that raise events

    840e6de2c

    Best regards,

    Perter Huang
    Microsoft Online Partner Support

    Get Secure! - www.microsoft.com/security
    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comment

    • Samuel R. Neff

      #3
      Re: Add &lt;NonSerializ ed()&gt; attribute to implicitly created xxxEvent private fields??


      That's a lot of code to fix a simple problem--the C# solution is fine
      for most cases and certainly would be good as an option in VB.NET.
      The proposed solution replaces a single attribute with ~13 lines of
      code (assuming the custom functions just marshal the calls to a
      declared non-serializable delegate).

      Best regards,

      Sam


      On Thu, 03 Feb 2005 08:54:36 GMT, v-phuang@online.m icrosoft.com
      ("Peter Huang" [MSFT]) wrote:
      [color=blue]
      >Hi
      >
      >Based on my understanding, you wants to mark a event in VB.NET as
      >NonSerialize d.
      >In C# 1.1 we have an attribute [field:NonSerial ized].
      >Unfortunatel y this is not supported in VB.NET on .net framework 1.1 and it
      >will be added in vb.net 2005.
      >Here is a link for your reference.
      >
      >NET 2.0 solution to serialization of objects that raise events
      >http://www.lhotka.net/WeBlog/PermaLi...-4845-b649-e0d
      >840e6de2c
      >
      >Best regards,
      >
      >Perter Huang
      >Microsoft Online Partner Support
      >
      >Get Secure! - www.microsoft.com/security
      >This posting is provided "AS IS" with no warranties, and confers no rights.[/color]

      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Add &lt;NonSerializ ed()&gt; attribute to implicitly created xxxEvent private fields??

        Peter,[color=blue]
        > In C# 1.1 we have an attribute [field:NonSerial ized].
        > ... it
        > will be added in vb.net 2005.[/color]
        Are you certain it will be added, Lhotka's sample does not show:

        <Field: NonSerialized> _
        Public Event NameChanged As EventHander

        Which is what most if not all of my serialization code needs, rarely do I
        need Custom Events that Rocky shows, where some of the handlers are
        serialized & some are not.

        I have classes that have multiple events, these classes are serialzed to
        files using Binary Serialization. The event handlers do not need to be
        serialized with the file, using <Field: NonSerialized> would save 12+ lines
        of code per event, which would reduce a significant amount of duplicate
        code!

        Also the above would solve *all* the questions I've seen on events being
        serialized in the newsgroups.

        VB.NET 2005 really needs both flavors, just as C# 1.0 supported both flavors
        ([field:NonSerial ized] & custom events).

        In other words, as Samuel suggests the custom event is an excessive amount
        of code for what is a simply problem in most cases...

        Hope this helps
        Jay

        ""Peter Huang" [MSFT]" <v-phuang@online.m icrosoft.com> wrote in message
        news:b2LrE4cCFH A.2944@cpmsftng xa10.phx.gbl...[color=blue]
        > Hi
        >
        > Based on my understanding, you wants to mark a event in VB.NET as
        > NonSerialized.
        > In C# 1.1 we have an attribute [field:NonSerial ized].
        > Unfortunately this is not supported in VB.NET on .net framework 1.1 and it
        > will be added in vb.net 2005.
        > Here is a link for your reference.
        >
        > NET 2.0 solution to serialization of objects that raise events
        > http://www.lhotka.net/WeBlog/PermaLi...-4845-b649-e0d
        > 840e6de2c
        >
        > Best regards,
        >
        > Perter Huang
        > Microsoft Online Partner Support
        >
        > Get Secure! - www.microsoft.com/security
        > This posting is provided "AS IS" with no warranties, and confers no
        > rights.
        >[/color]


        Comment

        • Peter Huang [MSFT]

          #5
          Re: Add &lt;NonSerializ ed()&gt; attribute to implicitly created xxxEvent private fields??

          Hi Jay,

          Thanks for your feedback.
          And I am sorry if I have made any mistake, in our internal document, we are
          planning to add the feature in vb 2005, since the whidbey is not released
          so far, so I can not guarantee if the feature will occur in the release
          version.

          Hope this helps.

          Best regards,

          Perter Huang
          Microsoft Online Partner Support

          Get Secure! - www.microsoft.com/security
          This posting is provided "AS IS" with no warranties, and confers no rights.

          Comment

          • Peter Huang [MSFT]

            #6
            Re: Add &lt;NonSerializ ed()&gt; attribute to implicitly created xxxEvent private fields??

            Hi Sam,

            Thanks for your feedback.
            We will try to keep improving our product to make VB.NET a more powerful
            dev tool.

            Best regards,

            Perter Huang
            Microsoft Online Partner Support

            Get Secure! - www.microsoft.com/security
            This posting is provided "AS IS" with no warranties, and confers no rights.

            Comment

            Working...