C# 4.0 使用介绍的成员?
我一直在阅读PostSharp,我想用简介来注入一名成员。举个愚蠢的例子,假设我写了一个方面C# 4.0 使用介绍的成员?,c#-4.0,postsharp,C# 4.0,Postsharp,我一直在阅读PostSharp,我想用简介来注入一名成员。举个愚蠢的例子,假设我写了一个方面 public Guid Id = Guid.NewGuid(); 很简单,如果我拆开,我会看到它在那里。现在是棘手的部分。。在同一个班级里,我想做一些事情,比如 public void PrintGuid() { Console.WriteLine(this.Id); } 我该怎么做?或者,如果这不起作用,我可以在类中声明变量,然后在方面中使用它吗?所以全班都会 public Guid I
public Guid Id = Guid.NewGuid();
很简单,如果我拆开,我会看到它在那里。现在是棘手的部分。。在同一个班级里,我想做一些事情,比如
public void PrintGuid()
{
Console.WriteLine(this.Id);
}
我该怎么做?或者,如果这不起作用,我可以在类中声明变量,然后在方面中使用它吗?所以全班都会
public Guid Id;
这个相位会做一些类似的事情
this.Id = Guid.NewGuid();
你可以在这里看到怎么做
var MyClass = Post.Cast<IMyInterface>(...);
MyClass.MyIntroducedMember = 10;
var MyClass=Post.Cast(…);
MyClass.MyIntroductedMember=10;
您在设计时找到了这样做的方法吗?