An annoyng Serialization problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carlo, MCP

    An annoyng Serialization problem

    Hello,

    I'm troubling from months with a serious serialization problem that I'm not able to solve. I try to describe as simply
    as I can.

    1) I have a class tha does something with colors. All default values are obviously NOT serializad. Instead, they are
    serialized when they are different from those of default. Sample:
    Class ColorClass
    Private mBackground=Col or.White
    Public Property Background
    'Wil be serialized if mBackground not equals to Color.White
    End Property
    End Class

    2) I have other classes (specifically they are components) that includes some properties linked to the above ColorClass.
    These classes use one or more instances of the ColorClass for their pourposes, setting appropriate colors each time for
    each element of the component. Sample:
    Class MyComponent
    Private MyTitleBackg as ColorClass
    Public Sub New()
    MyTitleBackg .Background=Col or.Green 'Here default of ColorClass changes: will be serialized
    End Sub
    <DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Content)> _
    Public Property MyTitleBackg
    'Get, Set, etc.
    End Property
    End Class

    If, at design-time, I change MyTitleBackg of MyComponent to Color.Red, new value (Color.Red) WILL be correctly
    serialized since it is different from BOTH the default of ColorClass and the default of MyComponent.

    But here is the problem: if, at design-time I change MyComponent.MyT itleBackg to Color.White, the new value
    (Color.White) WILL be NOT serialized, and regenerating assembly causes MyComponent.MyT itleBackg switch back to
    Color.Green.
    What happened? New value assigned at design-time (Color.White) is equal to the default of ColorClass, and therefore it
    is NOT serialized; after regeneration, the designer reads and set MyComponent.MyT itleBackg to the default color of the
    current instance of MyComponent (Color.Green).

    This is a problem, because I want MyComponent.MyT itleBackg.Backg round White, NOT Green!

    I confess that has not be simple understand the logic behind the problem, especially inside a medium-complessity class
    hierarchy. Please note that the problem occours with any type, non only colors.

    A solution should be force serialization by setting ShouldSerialize xxx=True (for every property) or by deleting
    defaults, but I don't consider this a solution: it's a brutality.

    Ok, if is there a way to avoid this annoyng mechanism, I've not found it.

    Please help me... Thank you.

    Carlo




    -------------------------------------------
    Carlo, MCP (Windows Based Applications)
    carlodevREMOVE@ gmail.com
    Milan, Italy



  • Shatru Singh

    #2
    Re: An annoyng Serialization problem

    Did you tried decorating the property procedures with default value
    attribute. Since the serialization manager will compare value with that of
    attribute.

    Shatru


    "Carlo, MCP" <carlodevREMOVE @gmail.com> wrote in message
    news:etrbuMLyFH A.700@TK2MSFTNG P11.phx.gbl...[color=blue]
    > Hello,
    >
    > I'm troubling from months with a serious serialization problem that I'm
    > not able to solve. I try to describe as simply as I can.
    >
    > 1) I have a class tha does something with colors. All default values are
    > obviously NOT serializad. Instead, they are serialized when they are
    > different from those of default. Sample:
    > Class ColorClass
    > Private mBackground=Col or.White
    > Public Property Background
    > 'Wil be serialized if mBackground not equals to Color.White
    > End Property
    > End Class
    >
    > 2) I have other classes (specifically they are components) that includes
    > some properties linked to the above ColorClass. These classes use one or
    > more instances of the ColorClass for their pourposes, setting appropriate
    > colors each time for each element of the component. Sample:
    > Class MyComponent
    > Private MyTitleBackg as ColorClass
    > Public Sub New()
    > MyTitleBackg .Background=Col or.Green 'Here default of ColorClass
    > changes: will be serialized
    > End Sub
    >
    > <DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Content)>
    > _
    > Public Property MyTitleBackg
    > 'Get, Set, etc.
    > End Property
    > End Class
    >
    > If, at design-time, I change MyTitleBackg of MyComponent to Color.Red, new
    > value (Color.Red) WILL be correctly serialized since it is different from
    > BOTH the default of ColorClass and the default of MyComponent.
    >
    > But here is the problem: if, at design-time I change
    > MyComponent.MyT itleBackg to Color.White, the new value (Color.White) WILL
    > be NOT serialized, and regenerating assembly causes
    > MyComponent.MyT itleBackg switch back to Color.Green.
    > What happened? New value assigned at design-time (Color.White) is equal to
    > the default of ColorClass, and therefore it is NOT serialized; after
    > regeneration, the designer reads and set MyComponent.MyT itleBackg to the
    > default color of the current instance of MyComponent (Color.Green).
    >
    > This is a problem, because I want MyComponent.MyT itleBackg.Backg round
    > White, NOT Green!
    >
    > I confess that has not be simple understand the logic behind the problem,
    > especially inside a medium-complessity class hierarchy. Please note that
    > the problem occours with any type, non only colors.
    >
    > A solution should be force serialization by setting
    > ShouldSerialize xxx=True (for every property) or by deleting defaults, but
    > I don't consider this a solution: it's a brutality.
    >
    > Ok, if is there a way to avoid this annoyng mechanism, I've not found it.
    >
    > Please help me... Thank you.
    >
    > Carlo
    >
    >
    >
    >
    > -------------------------------------------
    > Carlo, MCP (Windows Based Applications)
    > carlodevREMOVE@ gmail.com
    > Milan, Italy
    >
    >
    >[/color]


    Comment

    • Carlo, MCP

      #3
      Re: An annoyng Serialization problem

      Yes, I tried. The problem described in my post is exactly the same with both
      serialization methods: using DefaultValue method or using the pair
      Resetxxx/ShouldSerialize xxx method.

      Carlo


      [color=blue]
      > Did you tried decorating the property procedures with default value
      > attribute. Since the serialization manager will compare value with that of
      > attribute.
      >
      > Shatru
      >
      >
      > "Carlo, MCP" <carlodevREMOVE @gmail.com> wrote in message
      > news:etrbuMLyFH A.700@TK2MSFTNG P11.phx.gbl...[color=green]
      >> Hello,
      >>
      >> I'm troubling from months with a serious serialization problem that I'm
      >> not able to solve. I try to describe as simply as I can.
      >>
      >> 1) I have a class tha does something with colors. All default values are
      >> obviously NOT serializad. Instead, they are serialized when they are
      >> different from those of default. Sample:
      >> Class ColorClass
      >> Private mBackground=Col or.White
      >> Public Property Background
      >> 'Wil be serialized if mBackground not equals to Color.White
      >> End Property
      >> End Class
      >>
      >> 2) I have other classes (specifically they are components) that includes
      >> some properties linked to the above ColorClass. These classes use one or
      >> more instances of the ColorClass for their pourposes, setting appropriate
      >> colors each time for each element of the component. Sample:
      >> Class MyComponent
      >> Private MyTitleBackg as ColorClass
      >> Public Sub New()
      >> MyTitleBackg .Background=Col or.Green 'Here default of ColorClass
      >> changes: will be serialized
      >> End Sub
      >>
      >> <DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Content)>
      >> _
      >> Public Property MyTitleBackg
      >> 'Get, Set, etc.
      >> End Property
      >> End Class
      >>
      >> If, at design-time, I change MyTitleBackg of MyComponent to Color.Red,
      >> new value (Color.Red) WILL be correctly serialized since it is different
      >> from BOTH the default of ColorClass and the default of MyComponent.
      >>
      >> But here is the problem: if, at design-time I change
      >> MyComponent.MyT itleBackg to Color.White, the new value (Color.White) WILL
      >> be NOT serialized, and regenerating assembly causes
      >> MyComponent.MyT itleBackg switch back to Color.Green.
      >> What happened? New value assigned at design-time (Color.White) is equal
      >> to the default of ColorClass, and therefore it is NOT serialized; after
      >> regeneration, the designer reads and set MyComponent.MyT itleBackg to the
      >> default color of the current instance of MyComponent (Color.Green).
      >>
      >> This is a problem, because I want MyComponent.MyT itleBackg.Backg round
      >> White, NOT Green!
      >>
      >> I confess that has not be simple understand the logic behind the problem,
      >> especially inside a medium-complessity class hierarchy. Please note that
      >> the problem occours with any type, non only colors.
      >>
      >> A solution should be force serialization by setting
      >> ShouldSerialize xxx=True (for every property) or by deleting defaults, but
      >> I don't consider this a solution: it's a brutality.
      >>
      >> Ok, if is there a way to avoid this annoyng mechanism, I've not found it.
      >>
      >> Please help me... Thank you.
      >>
      >> Carlo
      >>
      >>
      >>
      >>
      >> -------------------------------------------
      >> Carlo, MCP (Windows Based Applications)
      >> carlodevREMOVE@ gmail.com
      >> Milan, Italy
      >>
      >>
      >>[/color]
      >
      >[/color]


      Comment

      Working...