Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't the Type class in the System.Reflection namespace?

Everything about Type is reflective in nature. Is it because Type is used more often than the rest of the classes in System.Reflection? Or because it functions more like a system class than a reflection class?

In short, I've always wondered what the motivation behind the location of System.Type was.

like image 269
Joe Avatar asked Nov 05 '22 15:11

Joe


2 Answers

The Type class is used in a lot more places, not just System.Reflection. A quick search with Reflector reveals hundreds of them. It is crucial in System.Configuration, System.Data, System.Drawing, System.Linq, System.Windows.Forms, etc. The way the Type instance is actually used in these classes isn't visible. It is likely that System.Reflection is used but that's an implementation detail that in no way affects the program.

Given that creating the Type instance that these classes need is trivial with the typeof operator and object.GetType and that you never have to use System.Reflection unless you actually write reflection code, Type certainly deserves an easily accessible location in the System namespace.

like image 200
Hans Passant Avatar answered Nov 15 '22 06:11

Hans Passant


An assembly has types and Assembly lies on System.Reflection which is curious.

So my guess would be that it has something to do with Object implementing the method GetType which returns a Type.

like image 24
João Angelo Avatar answered Nov 15 '22 05:11

João Angelo