0
votes

I'm looking at an XML specification which states that an enum needs to be encoded as a nullable uInt8.

<enum name="FTI" encodingType="uInt8NULL">
    <validValue description="Backup" name="Backup">0</validValue>
    <validValue description="Primary" name="Primary">1</validValue>

Hence, I create an enum, only to find out that it can't inherit from a nullable primitive type.

Is there any way to get around this, or is this by design?

public enum KeepAlivedLapsed : Byte?
{
    NotLapsed = 0,
    Lapsed = 1,
}

Error: CS1008 Type byte, sbyte, short, ushort, int, uint, long, or ulong expected

The same error happens when I inherit from Nullable<Byte>.

1

1 Answers

1
votes

What you need to do is create a normal enum and then use it as a nullable type:

public enum KeepAlivedLapsed : Byte
{
    NotLapsed = 0,
    Lapsed = 1,
}

KeepAlivedLapsed? value = null;