views:

65

answers:

2

Is there any point at all on inheriting from Type class in .Net?

i.e. What could be the meaning of doing so?

I am asking this because of this text in MSDN documentation:

Notes to Inheritors When you inherit from Type, you must override the following members... list of members.

MSDN doc for Type: http://msdn.microsoft.com/en-us/library/system.type.aspx

ok, that is actually saying that anyone can inherit from Type... but they dont say why would you ever want to do that.

Thanks!

A: 

I sometimes wish some of the other classes in the reflection libraries of .Net were derived from interfaces, as I have to do skin=and=wrap many of them when I write unit tests for my code-generation code.

For instance, it would be nice if there were an IMethodInfo interface that MethodInfo implmented. I could then write my FakeMethodInfo object for use in my unit tests.

The same idea goes for Type: I'd like to create a FakeType class that has the same interface as Type, but doesn't involve the CLR but instead returns fake data supplied by my unit testing code.

John Källén
I think it'd be nice if I could extend the Type returned for my own types... adding information to it, without having to use attributes.
Miguel Angelo
ICustomTypeDescriptor is very handy for classes that use System.Component.TypeDescriptor for reflection. You can in principle override everything with that interface. Many of the classes in the .NET framework involved with Windows Forms and other component technologies use this mechanism. I'm not aware of a mechanism to hook Object.GetType() though.
John Källén
+2  A: 

It all depends on what you are doing.

Here is one case. Maybe I need extra functionality on the Type class for use in my application at some point, lets say for logging. However then I need to pass it to a function that is expecting just the Type. I can pass my inherited class to that funciton without calling MyObject.GetType();

David Basarab