C#中派生类继承基类那么基类的特性有继承吗?

2025年03月12日 23:33
有1个网友回答
网友(1):

你的特性里面定义的是都为true,那么派生类当然是可以继承基类的特性的。你的这种获得特性的方式我没有用过,不过你可以换种方式试试看。Type type=typeof(CeshiClass);PasswordAttribute[] attributes=(PasswordAttribute[] )t.GetCustomAttributes(typeof(PasswordAttribute), true);-------------------------------注意这里的true就是是否要取继承过来的Attribute的。foreach(var p in attributes){ Console.WriteLine(p.Psw)
}希望能帮到你。