Reputation: 6725
My code is returning a blank array of PropertyInfo
PropertyInfo[] classProperties = typeof(Processor).GetProperties();
All properties in this class are public. Using .NET 2.0 Framework.
I have also tried using an instance declared earlier in my code:
PropertyInfo[] classProperties = Computer.Processor[0].GetType().GetProperties();
And I have tried using bindings such as Default, Instance and Public.
Any ideas?
Upvotes: 2
Views: 357
Reputation: 1064204
The parameterless form will return public properties. So there are 2 likely options:
A public property is something a: with the public
modifier, and b: with a get
or set
accessor, for example either of:
public int Foo {get;set;} // automatically implemented property
public string bar;
public string Bar { // manually implemented property
get { return bar; }
set { bar = value; }
}
Note also that interface-bound properties that are implemented as explicit interface implementation will only be reflected if you query against the interface, not the class; so the following will not show unless you start from typeof(ISomeInterface)
:
string ISomeInterface.Bar { get { return someValue; } }
Upvotes: 5