Reputation: 39
I need to introduce field, which value must be serialized with other fields of the class decorated by aspect.
This is my class:
[Serializable]
[MyAspect(1)]
public MyClass
{
public int IntField = 0;
}
and this is my aspect:
[Serializable]
public class MyAspect: InstanceLevelAspect
{
private int _aspectField;
public MyAspect(int aspectField)
{
_aspectField = aspectField;
}
[IntroduceMember]
public int IntroducedProperty { get; set; }
}
After decompiling dll, I see that IntroducedProperty has been added to MyClass definition, but it delegates all calls to MyAspect.IntroducedProperty, thereby to its backing field.
So, serialization do not see any field, corresponding to IntroducedProperty, in MyClass.
Also, PostSharp generates field of MyAspect type in MyClass, that marked by NonSerializable attribute.
Are there some ways to introduce field, that would participate in serialization?
Upvotes: 2
Views: 351
Reputation: 39
Solved here: http://support.sharpcrafters.com/discussions/questions/742-how-to-introduce-property-for-serialization
I need to implement ISerializable interface in MyClass, or introduce that interface by aspect
Upvotes: 2