【发布时间】:2014-03-25 13:03:01
【问题描述】:
我需要引入字段,该值必须与被切面修饰的类的其他字段序列化。
这是我的课:
[Serializable]
[MyAspect(1)]
public MyClass
{
public int IntField = 0;
}
这是我的方面:
[Serializable]
public class MyAspect: InstanceLevelAspect
{
private int _aspectField;
public MyAspect(int aspectField)
{
_aspectField = aspectField;
}
[IntroduceMember]
public int IntroducedProperty { get; set; }
}
反编译 dll 后,我看到 IntroducedProperty 已添加到 MyClass 定义中,但它会将所有调用委托给 MyAspect.IntroducedProperty,从而委托给它的支持字段。
所以,序列化在 MyClass 中看不到任何对应于 IntroducedProperty 的字段。
另外,PostSharp 在 MyClass 中生成 MyAspect 类型的字段,由 NonSerializable 属性标记。
有没有办法引入字段,参与序列化?
【问题讨论】:
-
我见过的所有序列化程序都只对属性进行操作,而不是对字段进行操作。
-
我正在使用 BinaryFormatter,它对字段进行操作
标签: c# serialization aop postsharp binaryformatter