Isn't it odd that...

From the files of things that make you go “hmmmm”.

 

System.Exception (the base class for all exceptions) is indeed an exception: throw new Exception ()

 

But…

System.Enum (the base class for all enums) is not an enum: typeof (Enum).IsEnum == false

System.ValueType (the base class for all ValueTypes) is not a ValueType: typeof (ValueType).IsValueType == false

System.Attribute (the base class for all custom attributes) is not a custom attribute [Attribute] -> compile error

From the files of things that make you go “hmmmm”.

 

System.Exception (the base class for all exceptions) is indeed an exception: throw new Exception ()

 

But…

System.Enum (the base class for all enums) is not an enum: typeof (Enum).IsEnum == false

System.ValueType (the base class for all ValueTypes) is not a ValueType: typeof (ValueType).IsValueType == false

System.Attribute (the base class for all custom attributes) is not a custom attribute [Attribute] -> compile error.

 

 

There is, of course, good reason for all of this, but still a bit odd when you try to explain to someone the first time.

Published 08 May 04 07:39 by BradA
Filed under:

Comments

# Martin Mueller said on May 9, 2004 4:23 AM:
Even odder (pun intended) is that <b>System.Reflection</b> thinks of poor <b>System.Enum</b> as the only true orphan in the whole type system:

- typeof (System.Enum).IsEnum returns false : OK, since its no enum
- typeof (System.Enum).IsValueType returns false : OK, since its no struct
- typeof (System.Enum).IsInterface returns false : OK, since its no interface
- typeof (System.Enum).IsClass returns false : Error ??

According to section 14.4 of the C# spec, <b>System.Enum</b> is the abstract base <b>class</b> of all enums, so i think <b>IsClass</b> should return true, but it doesnt. For every other type, at least one of the four IsXYZ properties listed above returns true.

Is that a bug in Net 1.1 ?
If not, why not ?
If yes, will it be fixed in Net 1.x / 2.x ?
# Miguel de Icaza said on May 9, 2004 10:44 AM:
Heh, we ran into that in our C# compiler, as the first pass
blindly assumed the intuitive behavior, but you must generate
code differently as explained above.

Miguel.
# Ken Brubaker said on May 10, 2004 9:36 AM:
I guess that's why they made Type.IsSubclassOf rather than IsTypeOrSubclass. :-)
# Om said on May 10, 2004 11:54 AM:
It' something we can compare to the Russell paradox
# Joel Pobar said on May 10, 2004 12:50 PM:
typeof(System.Enum).IsXXXX does behave strangely, and is more that likely a bug. We'll take a look at that soon, and hopefully have a fix if it's deemed a problem.
# Brad Abrams said on May 10, 2004 9:21 PM:
Oh, and I just noticed that System.Array is not an Array:
typeof (Array).IsArray = false...
# Corneliu said on May 10, 2004 9:51 PM:
panel1 is a child of Form1
label1 is a child of panel1.
All are visible.

panel1.Visible = false;
label1.Visible = label1.Visible;
panel1.Visible = true;

What will now be visible?
panel1 only!!. label1 will be hidden ..
Right .. cose Visible returns the visiblity of it's parents also.
Why?

Corneliu.
# Web Log di Adrian Florea said on March 30, 2005 5:50 PM:
# More Horrors « Bug Vanquisher said on November 11, 2007 5:46 AM:

PingBack from http://tanveerbadar.wordpress.com/2007/11/11/more-horrors/

New Comments to this post are disabled

Search

Go

This Blog

Syndication

Page view tracker