Undocmumented Class System.RuntimeType

  • Thread starter Thread starter Stofdeel
  • Start date Start date
S

Stofdeel

Heya,

I am looking for information about the System.RuntimeType and other Runtime
classes. They are undocumented in my version of Visual Studio. So far I have
no luck with internet, only some remarks:

- All .NET classes are instances of System.RuntimeType.

- RuntimeType is the basic Type object representing classes as found in the
system.

- This type is never creatable by users, only by the system itself.

- The internal structure is known about by the runtime.

- __RuntimeXXX classes are created only once per object in the system and
support == comparisions.


Any links would be helpfull,

Thanks.
 
Hi,
These remarks that you have posted have been taken from rotor
\sscli\clr\src\bcl\system\runtimetype.cs? You can look at different places
in Rotor for RuntimeType and will find a lot of comments that may help
understanding more about it.

Ab.
http://joehacker.blogspot.com
 
Stofdeel,
| I am looking for information about the System.RuntimeType and other
Runtime
| classes.
Why? System.RuntimeType is a specific implementation of System.Type. You
should be programming to the public "contract" of System.Type, not the
private implementation details of System.RuntimeType.

| They are undocumented in my version of Visual Studio. So far I have
| no luck with internet, only some remarks:
IMHO RuntimeType is undocumented as it is an implementation detail of the
Framework, i.e. it encapsulates the "runtime" implementation of a Type.
Remember that Encapsulation is one of the tenants of OO.

| - All .NET classes are instances of System.RuntimeType.
That is not really true, I would say most .NET System.Type instances are
instances of System.RuntimeType. I don't remember if when you load a type
for with System.Reflection if its still a System.RuntimeType or another
concrete Type. Although I don't have specific examples, I would expect there
may be other private specific implementations of System.Type, as System.Type
is MustInherit (abstract) after all.

In other words I would not (*do not*) expect that all System.Type variables
are of type System.RuntimeType.

| - RuntimeType is the basic Type object representing classes as found in
the
| system.
I would agree to a point, ergo an Encapsulated Implementation Detail. As I
suggested earlier I would program to System.Type and not be concerned with
what System.RuntimeType is.

For example: consider the System.IO.Stream.Null property. If you look at the
object return it has type System.IO.Stream.NullStream. NullStream is not
documented as it is an implementation detail of the Stream.Null property.
All one really needs to know is that Stream.Null returns an implementation
of Stream that behaves like a stream...

| - This type is never creatable by users, only by the system itself.
Again I would agree, ergo an Encapsulated Implementation Detail

| - __RuntimeXXX classes are created only once per object in the system
| and
| support == comparisons.
Do you mean reference equality (Is operator), or identity equality (=
operator). As == is an C# operator that could mean either.

I don't see that Identity equality is supported as: I don't see operator =
overloaded, nor System.Equals overridden, nor IComparable implement.
Of course reference equality is supported as specific types are effectively
singletons...


--
Hope this helps
Jay [MVP - Outlook]
T.S. Bradley - http://www.tsbradley.net


| Heya,
|
| I am looking for information about the System.RuntimeType and other
Runtime
| classes. They are undocumented in my version of Visual Studio. So far I
have
| no luck with internet, only some remarks:
|
| - All .NET classes are instances of System.RuntimeType.
|
| - RuntimeType is the basic Type object representing classes as found in
the
| system.
|
| - This type is never creatable by users, only by the system itself.
|
| - The internal structure is known about by the runtime.
|
| - __RuntimeXXX classes are created only once per object in the system and
| support == comparisions.
|
|
| Any links would be helpfull,
|
| Thanks.
|
|
 
Thanks all for the replies.
| I am looking for information about the System.RuntimeType and other
Runtime
| classes.
Why? System.RuntimeType is a specific implementation of System.Type. You
should be programming to the public "contract" of System.Type, not the
private implementation details of System.RuntimeType.

The code should be able to recognize them:

Public Sub Test(objType As System.Type)
If type = RuntimeType or other RuntimeXXX type then
"Nope, can't do, go away."
End If
End Sub
 
Qwert,
| The code should be able to recognize them:
| If type = RuntimeType or other RuntimeXXX type then
If you really want to rely on an implementation detail, then you could use a
string comparison.

If type.ToString = "String.RuntimeType"

However I still question why! As relying on implementation details usually
creates fragile code.

About the only time I would care if its a runtime type or not, is when I
have introduced specific Type types. And I need to operate specifically on
my specific Type types. In which case rather then check for RuntimeType,
which I don't know about, I would be checking for my specific Type types.
This way if others create specific Type types I don't need to change the
logic to include those types also...

--
Hope this helps
Jay [MVP - Outlook]
T.S. Bradley - http://www.tsbradley.net


| Thanks all for the replies.
|
| > | I am looking for information about the System.RuntimeType and other
| > Runtime
| > | classes.
| > Why? System.RuntimeType is a specific implementation of System.Type. You
| > should be programming to the public "contract" of System.Type, not the
| > private implementation details of System.RuntimeType.
|
| The code should be able to recognize them:
|
| Public Sub Test(objType As System.Type)
| If type = RuntimeType or other RuntimeXXX type then
| "Nope, can't do, go away."
| End If
| End Sub
|
|
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top