We currently generate a helper class for enums, and it's the only construct with a separate helper class (the generated struct/class is usually its own "helper").
This helper class provides 3 extension methods, but none of them are for the enum itself. For example:
/// <summary>Helper class for marshaling and unmarshaling <see cref="MyEnum"/>.</summary>
public static class MyEnumHelper
{
public static readonly global::System.Collections.Generic.HashSet<int> EnumeratorValues =
new global::System.Collections.Generic.HashSet<int> { 0, 1, 10, 11, 20, 21, 30, 31, 40, 41, 226 };
public static MyEnum AsMyEnum(this int value) =>
EnumeratorValues.Contains(value) ?
(MyEnum)value :
throw new IceRpc.InvalidDataException($"invalid enumerator value '{value}' for MyEnum");
public static MyEnum DecodeMyEnum(this ref SliceDecoder decoder) =>
AsMyEnum(decoder.DecodeSize());
public static void EncodeMyEnum(this ref SliceEncoder encoder, MyEnum value) =>
encoder.EncodeSize((int)value);
}
I propose to move the EncodeXxx method to a class named SliceEncoderXxxExtensions, and DecodeXxx to a class named SliceDecoderXxxExtensions.
EnumeratorValues and AsXxx could go into a class named IiiXxxExtensions where Iii = byte, int, uint (...) as appropriate.
We currently generate a helper class for enums, and it's the only construct with a separate helper class (the generated struct/class is usually its own "helper").
This helper class provides 3 extension methods, but none of them are for the enum itself. For example:
I propose to move the EncodeXxx method to a class named SliceEncoderXxxExtensions, and DecodeXxx to a class named SliceDecoderXxxExtensions.
EnumeratorValues
andAsXxx
could go into a class named IiiXxxExtensions where Iii = byte, int, uint (...) as appropriate.