Why are only attributes on public members possibl?

Topics: CAB & Smart Client Software Factory
Dec 1, 2006 at 5:48 AM
originally posted by: JoukeNuman

Objectbuilder and CAB only take public members into account for attribute searches
(see Microsoft.Practices.ObjectBuilder.PropertyReflectionStrategy and Microsoft.Practices.CompositeUI.EventBroker.EventInspector). This leads to the following problems:
1: If attribute is placed on non-public member, it is silently (no errors) ignored when application runs. This (coding) error can be difficult to trace.
2: Because visibility must be public, it can add an unwanted entry point in the class coding. Two examples:
- ServiceDependency can be added to a property, but because it must be public, anyone can call it.
Better would be to be able to declare private.
- EventSubscription can be added to a method. That method can now be called direct, which gives an
extra (unwanted) entry point to the class besides through the EventBroker.

My suggestion would be to also take non-public members into account and let the type of property decide which visibility is required (eg. InjectionConstructor should require public, ServiceDependency should require private)
Dec 1, 2006 at 6:09 AM
originally posted by: hmoeller

It's simply a matter of performance. Private reflection has much more impact to performance than public reflection has. Of course, you could modify the strategies to also do private reflection. But be prepared for performance issues.