E
Eric Jacoboni
Hi,
I've some question about best programming practice in C#.
Suppose i want a serializable class with transient member and recreate
this member on deserialization.
I've found i may use these two approaches:
1) Using interfaces:
[Serializable]
class Truc : IDeserializationCallback {
private int limite;
[NonSerialized]
private int[] tab;
(...)
public virtual void OnDeserialization(Object sender) { ... }
}
2) Using attributes only:
[Serializable]
class Truc {
private int limite;
[NonSerialized]
private int[] tab;
(...)
[OnDeserialized]
public virtual void OnDeserialized(StreamingContext context)
{ ... }
}
Both do what i expect but i wonder if one approach is considered better
than the other.
Any advice?
I've some question about best programming practice in C#.
Suppose i want a serializable class with transient member and recreate
this member on deserialization.
I've found i may use these two approaches:
1) Using interfaces:
[Serializable]
class Truc : IDeserializationCallback {
private int limite;
[NonSerialized]
private int[] tab;
(...)
public virtual void OnDeserialization(Object sender) { ... }
}
2) Using attributes only:
[Serializable]
class Truc {
private int limite;
[NonSerialized]
private int[] tab;
(...)
[OnDeserialized]
public virtual void OnDeserialized(StreamingContext context)
{ ... }
}
Both do what i expect but i wonder if one approach is considered better
than the other.
Any advice?