CJx*_*JxD 2 c# reflection properties
我的代码返回一个PropertyInfo的空白数组
PropertyInfo[] classProperties = typeof(Processor).GetProperties();
Run Code Online (Sandbox Code Playgroud)
此类中的所有属性都是公共的.使用.NET 2.0 Framework.
我也尝试使用我的代码中先前声明的实例:
PropertyInfo[] classProperties = Computer.Processor[0].GetType().GetProperties();
Run Code Online (Sandbox Code Playgroud)
我尝试过使用Default,Instance和Public等绑定.
有任何想法吗?
无参数表单将返回公共属性.所以有两种可能的选择:
公共属性是:使用public修饰符,b:使用get或set访问者,例如:
public int Foo {get;set;} // automatically implemented property
public string bar;
public string Bar { // manually implemented property
get { return bar; }
set { bar = value; }
}
Run Code Online (Sandbox Code Playgroud)
另请注意,实现为显式接口实现的接口绑定属性仅在您对接口而不是类进行查询时才会反映出来.所以除非你从以下开始,否则以下内容不会显示typeof(ISomeInterface):
string ISomeInterface.Bar { get { return someValue; } }
Run Code Online (Sandbox Code Playgroud)