I'm trying to read all of the properties of a given object, reading in only those that are declared on the object's type, excluding those that are inherited. IE:
class Parent { public string A { get; set; } } class Child : Parent { public string B { get; set; } }
And so I want to only get B back. Reading the docs, I assumed below was what I needed, but that actually returned nothing at all.
var names = InstanceOfChild.GetType().GetProperties(BindingFlags.DeclaredOnly).Select(pi => pi.Name).ToList();
CSS properties such as height , width , border , margin , padding , etc. are not inherited.
CSS height and width Valuesauto - This is default. The browser calculates the height and width.
Just need a couple other BindingFlags
var names = InstanceOfChild.GetType().GetProperties( BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance).Select(pi => pi.Name).ToList();
Try this:
var names = InstanceOfChild.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Select(pi => pi.Name).ToList();
I added the BidningFlags.Instance
and BindingFlags.Public
to the search parameters which according to the MSDN documentation respectfully:
Specifies that instance members are to be included in the search.
and
Specifies that public members are to be included in the search.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With