Exemple #1
0
        internal T ReadEnum <T>(EmberReader reader, string fieldName)
            where T : struct
        {
            Exception exception = null;

            try
            {
                var result = FastEnum.ToEnum <T>(reader.AssertAndReadContentsAsInt32());

                if (FastEnum.IsDefined(result))
                {
                    return(result);
                }
            }
            catch (ModelException ex)
            {
                exception = ex;
            }

            const string Format = "The field {0} has an unexpected value for the element with the path {1}.";

            throw new ModelException(
                      string.Format(CultureInfo.InvariantCulture, Format, fieldName, this.GetPath()), exception);
        }
Exemple #2
0
 public static TEnum ToFastEnum <TEnum>(this string val) where TEnum : struct
 {
     return(FastEnum <TEnum> .ToEnum(val));
 }
 internal sealed override TEnum?ReadValue(EmberReader reader, out ParameterType?parameterType)
 {
     parameterType = ParameterType.Enum;
     return(FastEnum.ToEnum <TEnum>(reader.AssertAndReadContentsAsInt64()));
 }
        internal sealed override TEnum?AssertValueType(object value)
        {
            var integer = value as long?;

            return(integer.HasValue ? FastEnum.ToEnum <TEnum>(integer.Value) : base.AssertValueType(value));
        }