我具有此属性:
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
public class PersonAttribut : Attribute
{
Person person;
public PersonAttribut(Person perosn)
{
this.person = person;
if (.............)
{
throw new Exception("My comment");
}
}
}
在课堂上:
public abstract class MyPersonBase
{
protected readonly Person person;
public MyPersonBase(Person person)
=> this.person = person;
}
public class MyPerson : MyPersonBase
{
public MyPerson(Person person) : base(person)
{
}
[Person(person)]
public void MyMethod(Person person)
{
}
}
我想将作为参数(请参见方法:MyMethod
)发送给基类person
的值MyPersonBase
到属性,但出现此错误:
非静态字段,方法或属性需要对象引用
我该怎么办?
答案 0 :(得分:-2)
您看到您刚刚写完了
public PersonAttribut(Person perosn)
代替
public PersonAttribut(Person person)
?