0

我对 PostSharp 有疑问。像这样的代码:

class Program
{
    static void Main(string[] args)
    {
    }
}

interface IA
{
    int a { get; set; }
}

[Serializable]
[IntroduceInterface(typeof(IA))]
public class Aaaa : InstanceLevelAspect, IA
{
    public int a { get; set; }
}

[Serializable]
[Aaaa]
class B
{
}

使用 PostSharp 2.0 构建提供了类 B,该类可通过接口 IA 中的字段进行序列化。使用 PostSharp 2.1 IA 文件构建后不会序列化。反编译后,我得到该代码:

[Serializable]
private class B : IA
{
  [NonSerialized]
  private Aaaa <>__aspect1;

  public B()
  {
    base.\u002Ector();
    this.\u003C\u003Ez__InitializeAspects();
  }

  {...}
}

在 2.0 版中,代码几乎相同,但有一处不同。没有 [NonSerialized] 属性。有什么办法让它在 2.1 上像在 2.0 上一样工作吗?

4

1 回答 1

0

这是设计使然。PostSharp 2.0 中的行为被认为是错误的,并在 2.1 中修复。没有办法回到旧的行为。

于 2013-07-10T19:10:21.957 回答