C# 波斯夏普。如何引入可序列化属性

C# 波斯夏普。如何引入可序列化属性,c#,serialization,aop,postsharp,binaryformatter,C#,Serialization,Aop,Postsharp,Binaryformatter,我需要引入字段,该字段的值必须与由方面修饰的类的其他字段序列化 这是我的班级: [Serializable] [MyAspect(1)] public MyClass { public int IntField = 0; } 这就是我的观点: [Serializable] public class MyAspect: InstanceLevelAspect { private int _aspectField; public MyAspect(int aspectFi

我需要引入字段,该字段的值必须与由方面修饰的类的其他字段序列化

这是我的班级:

[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之后,我看到IntroductProperty已添加到MyClass定义中,但它将所有调用委托给MyAspect.IntroductProperty,从而委托给其支持字段

因此,序列化在MyClass中看不到任何与IntroductProperty对应的字段

此外,PostSharp在MyClass中生成MyAspect类型的字段,该字段由非序列化属性标记

是否有一些方法可以引入参与序列化的字段?

在这里解决:


我需要在MyClass中实现ISerializable接口,或者按方面引入该接口

我见过的所有序列化程序都只对属性而不是字段进行操作。我使用的是对字段进行操作的BinaryFormatter