Inherit from class type .Net

Is there any point when inheriting from the Type class in .Net?

i.e. What is the meaning of this?

I ask about this because of this text in the MSDN documentation:

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

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

ok, it actually means that someone can inherit from Type ... but they donโ€™t say why you ever want to do this.

Thanks!

+4
source share
2 answers

It all depends on what you do.

Here is one case. I might need additional functionality of the Type class to use in my application at some point, say, for logging. However, then I need to pass it to a function that expects only Type . I can pass my inherited class to this function without calling MyObject.GetType() ;

+2
source

Sometimes I would like some of the other classes in the .Net reflection libraries to be derived from interfaces, since I have to do skin = and = wrap many of them when I write unit tests for code generating code.

For example, it would be nice if there was an IMethodInfo interface that was implemented in MethodInfo. Then I could write my FakeMethodInfo object for use in my unit tests.

The same thing applies to the type: I would like to create a FakeType class that has the same interface as Type, but does not include the CLR, and instead returns fake data provided by my unit test code.

0
source

Source: https://habr.com/ru/post/1308467/


All Articles