Re: Compiler Error CS0702
- From: PIEBALD <PIEBALD@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 17 Apr 2008 12:55:00 -0700
my bias is towards explaining how the specification adequately describeswhat you're seeing
No, the specification doesn't. Certainly the specification allows the
keywords class and struct as constraints while (regrettably) omitting enum
(and delegate and event), so perhaps one can read _that_ as a statement in
your favor. But...
From a language standpoint (not an implementation standpoint) I see noreason to omit enum as a constraint in the first place.
If an implementer (and there _could_ conceivably be many implementations for
various platforms) chooses to implement enum as a class, then that class
_should_ be allowed as a constraint. But while Microsoft chose to use a class
to implement enums, for some unexplained reason, they also chose to make it
"special".
The fact is, you
can't constrain your type parameters to the System.Enum. You can insist
that the specification doesn't address that issue all you want, it's not
going to change how things work.
No, the specification knows nothing of System.Enum, that's merely a matter
of implementation.
The specification says that if a type has a base class you can use that base
class as a constraint. But, when implementing .net and its associated
compiler, someone decided that that shouldn't hold true for some classes even
though there appears to be no reason for that decision.
By the way, in the ECMA specification, they suggest using a static
constructor for checking the constraint, for situations where the language
doesn't support the constraint you want. That would at least ensure that
the constraint is checked only once, when you first use the class with
that specific enum type, rather than for each instance of the class you
create.
I'll take a look.
.
- Follow-Ups:
- Re: Compiler Error CS0702
- From: Jon Skeet [C# MVP]
- Re: Compiler Error CS0702
- From: Peter Duniho
- Re: Compiler Error CS0702
- References:
- Compiler Error CS0702
- From: PIEBALD
- Re: Compiler Error CS0702
- From: Peter Duniho
- Re: Compiler Error CS0702
- From: Peter Duniho
- Re: Compiler Error CS0702
- From: PIEBALD
- Re: Compiler Error CS0702
- From: Peter Duniho
- Compiler Error CS0702
- Prev by Date: String array intersections
- Next by Date: Re: Compiler Error CS0702
- Previous by thread: Re: Compiler Error CS0702
- Next by thread: Re: Compiler Error CS0702
- Index(es):
Relevant Pages
|
Loading