Search code examples
.netreflection

.NET Reflection Helper API?


When using reflection we typically just was the basic System.Reflection API but I am wondering if anyone know of a nice "wrapper" layer or API that has a more "schema style" approach? (e.g. kind of like a code generators DB schema view)

This is for use in code generators, like T4 templates etc...


Solution

  • See Type Descriptor Overview. Most people use it for designtime awesomeness since it allows you to create new/hide existing properties, or totally modify how a control is represented in Visual Studio's property box. However, it works just as well in runtime as designtime. For example, calling TypeDescriptor.GetProperties will get you all the properties of a type or object (instance-specific properties) from whatever TypeDescriptorProvider that is registered for that type/object. You can chain them, and there's a default provider that uses the old reflection technology if nothing more specific is registered.

    This basically means that calling GetProperties on your plugin would allow that plugin to show more settings that it really has, and allow it to persist those in any way it wants, which brings in some awesome scenarios for custom property boxes or reflection visualizers.