Is there an attribute that hides a member (specifically a property) from typeof(MyType).GetProperties()
in .net?
I'm looking for a quick fix - i.e. not creating custom attributes etc..
thanks
Is there an attribute that hides a member (specifically a property) from typeof(MyType).GetProperties()
in .net?
I'm looking for a quick fix - i.e. not creating custom attributes etc..
thanks
No.
Reflection allows one to see everything, including members marked private.
(In the end reflection uses the same metadata that the CLR, including the JIT, uses.)
That particular overload of GetProperties (without parameters) only returns the public properties. So you could mark the property as private/internal. Otherwise, I concur with Richard above.
Have a look into PropertyDescriptor instead of PropertyInfo.
These can be provided by overriding the 2 Properties methods in a derived class of TypeConverter.
With a little bit of ingenuity, you can pretty much make it do anything.
I currently use this to provide a flat list of properties for various cultures and values for translation purposes, and feed this to a PropertyGrid, while the class structure looks like:
class TagName
{
Culture culture;
string content;
}
[TypeConverter(typeof(TagConverter))]
class Tag
{
TagName[] tagNames;
}
Within the PropertyDescriptor you have complete control how values are set and get via a specific PropertyDescriptor instance.
Had it been possible, Microsoft would have been the first to do it themselves for .NET Assemblies :).