Re: Compiler Error CS0702



my bias is towards explaining how the specification adequately describes
what 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 no
reason 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.
.



Relevant Pages

  • Re: Enums in a database
    ... a lookup table is more flexible than an enum because you can ... database constraint can be used to ensure that you'll never get a number in a ... public enum Specialty ... INSERT AutoMechanics SELECT 'Fred', 0 -- ForeignCars ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Compiler Error CS0702
    ... Enum and delegate could indeed be useful. ... kind of type - it would be like having a "property" constraint. ... If an implementer (and there _could_ conceivably be many implementations for ... inherits from type object. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Compiler Error CS0702
    ... enum as a type constraint? ... directly leads you to believe that you should be able to specify an enum ... type as a constraint for a generic? ... Provides the base class for enumerations. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Compiler Error CS0702
    ... An enum is still basically a value type...that is, it behaves more like a value type than a reference type, and it's reference types that can be used as a constraint. ... You want to constrain the generic to only support enums, so of course you're predisposed to not read the information in a way that would contradict that. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: enum for a column
    ... the closest thing to an enum in TSQL is a check constraint. ... > I have a column that should contain one of a fixed set of values. ... > size char and create a check constraint that tests for each possible value. ...
    (microsoft.public.sqlserver.programming)

Loading