TypeDescriptor - Generic?

Topics: Developer Forum
Coordinator
Apr 22, 2008 at 9:06 PM
Hey has anyone considered making TypeDesciptor generic? Seems like it would get rid of boiler plate code and provide a bunch of infered strong typing.

Thanks again for this great framework.
Coordinator
Apr 23, 2008 at 1:02 AM
Dane

Short Answer: It’s a design decision.

Long Answer: The problem with generics is that you need to know the Type at compile time (Yes. You can create them at run time using reflection but that defeats the purpose). This would place some limitations on the usages of TypeDescriptor. One example is a common data layer that validates object before they go into the database. It cannot reference business code and hence could not make use of a generic TypeDescriptor.

There is the option of using the pattern “Generic class inheriting from non generic class”. This is a fairly common pattern in frameworks today and gives you the best of both worlds. You can choose to use the generic or non generic version of a class. I did consider this but decided against it on the “code bloat versus benefit” reason. If I apply this pattern across the framework I would need to do so on a large number of classes. Some of these include

  • PropertyDescriptor
  • FieldDescriptor
  • ParameterDescriptor
  • ValidatableBase
  • NotifyValidatableBase
  • etc etc

When you extrapolate this across the entire framework, examples, unit test and quick starts it is a huge amount of code.

Do you have a specific scenario that you think would be made much easier with generics? If so can you post some code?

BTW: I am not against making more use of generics in the future. I am simply cautious of how I make use of them.

Regards and thanks for the feedback :)

Simon

Coordinator
Apr 23, 2008 at 5:46 AM
Simon,

I agree with that choice. Makes sense. I'll have to wait until I'm using this enough to give feedback about pain points and my 2cents on wether or not its worth resolving them with generics. It was more or less a "has this been considered and found impossible" question.

Will report back when I'm in a better position to ;)

Keep up the good work,
Dane