5

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.

Joe
  • 16,328
  • 12
  • 61
  • 75
  • It could be because it's the mechanism of reflection. It's like your eyes. You will never actually see your eyes. You'll only, at best, see the reflection of your eyes. – Chuck Conway Mar 19 '10 at 14:47
  • Sure, the eyes are a mechanism to see one's own reflection. Though the comment only strengthens the question. Since you can't directly see your own eyes (i.e. can't directly see type info), you need some kind of reflection to get any information (i.e. `Type`). – Joe Mar 19 '10 at 19:10

3 Answers3

1

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.

João Angelo
  • 56,552
  • 12
  • 145
  • 147
  • 1
    Incidentally, `Object.getClass` in Java parallels this. – Josh Lee Mar 19 '10 at 14:45
  • Though by the same logic, shouldn't `MemberInfo` be in the `System` namespace as well? `Type` implements `GetMember()` which returns a `MemberInfo`. Forward-referencing of namespaces happens all over the place within the BCL. – Joe Mar 20 '10 at 15:31
  • @Arc, indeed, but the use case `Object.GetType()` is much more frequently used than `Object.GetType().GetMember()`. – João Angelo Mar 21 '10 at 11:38
  • Very true, though if `Type` is in `System.Reflection` you could still do `o.GetType.FullName` without needing any extra using blocks. Using `Type` for anything else usually requires `using System.Reflection` even when it's located in `System`. – Joe Mar 21 '10 at 20:43
1

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
0

I guess it's because Object as a GetType method.

MS coding practicing tell that a class should not reference a type in a subnamespace. In practice, the BCL violates this rule quite often ;o)

Cédric Rup
  • 15,468
  • 3
  • 39
  • 30