0

I got a class containing integer,bool,string and list (of integer). Each variable that need to be serialize in that class has a public property. When i deserialize my class via XmlSerializer the public property of each variable is call. Except the variable that are list of. The List of varaibles are weel deserialisze but the property setter isn't called.

Here is the property :

Public Property Ana_Offset As List(Of Integer)
    Get
        Return _Ana_Offset
    End Get
    Set(value As List(Of Integer))
        Tmp_Val = _Ana_Offset
        _Ana_Offset = value

        RaiseEvent VariableChanged(_Ana_Offset, Tmp_Val, "_Ana_Offset", 0)
    End Set
End Property

The class is something like this

<Serializable()> Public Class SACCVar

    Private _Code_Produit As String
    Private _Ana_Offset As New List(Of Integer)

    Public Event VariableChanged(ByVal Val As Object, ByVal Old_Val As Object, desc As String, index As Integer)

    End Class

The strange fact i just realise while posting is that i got no Set "event" but the get event is fired wit no data return, but for other variable the get isn't fired..?

Thanks for help

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
got_fr
  • 39
  • 8
  • Since `Ana_Offset ` is a List, serializers can simply `Add` to it. They need not create a list and assign it. Which may expose a flaw: your code can change list elements as well with no event firing – Ňɏssa Pøngjǣrdenlarp Mar 07 '16 at 15:30
  • Ok and do you have a way to get an event on the `add` method? – got_fr Mar 07 '16 at 15:43
  • Why do you want the event to fire when deserializing? Cant you run a method afterwards to process the whole list since the whole list changed as a result? Usually, you want to suppress those events when de/serializing. It doesnt help the other part - your code could change the list directly too – Ňɏssa Pøngjǣrdenlarp Mar 07 '16 at 16:05
  • When deserializing a writable collection (like `List`), `XmlSerializer` will use the pre-existing collection if one exists and not set it back. If it needs to allocate the collection, it will do so and then set it back immediately, *before populating it*. (This allows for serialization of [read-only collection properties](https://msdn.microsoft.com/en-us/library/ms182327.aspx).) You will need to use an observable collection or proxy array property as in https://stackoverflow.com/questions/27927496/xml-deserialization-of-collection-property-with-code-defaults – dbc Mar 07 '16 at 18:41
  • Thanks all. @plutonix i started writing the method but i was searching a way not to do that as all the code was ever written... – got_fr Mar 08 '16 at 08:00

0 Answers0