private object GetOptionNumber <TEnum>(TEnum option)
            where TEnum : struct
        {
            var underlyingType = _enum.GetUnderlyingType(option.GetType());

            return(Convert.ChangeType(option, underlyingType));
        }
Ejemplo n.º 2
0
        public void HandleGetSize(TypeHandlingContext context)
        {
            IEnum enumType = context.Type.GetEnumType();

            if (enumType == null)
            {
                throw new NotSupportedException();
            }

            IType baseType = enumType.GetUnderlyingType();

            context.Builder.AppendFormat("{1} += sizeof({0});", baseType.GetPresentableName(context.PresentationLanguage), context.GetSizeVariableName());
        }
            public static EnumContractInfo TryCreate([CanBeNull] IEnum enumType)
            {
                if (enumType != null && enumType.HasAttributeInstance(PredefinedType.FLAGS_ATTRIBUTE_CLASS, false))
                {
                    var numericTypeInfo = CSharpNumericTypeInfo.TryCreate(enumType.GetUnderlyingType());
                    if (numericTypeInfo != null)
                    {
                        Debug.Assert(enumType.EnumMembers != null);

                        return(numericTypeInfo.TryCreateEnumFlags(enumType.EnumMembers));
                    }
                }

                return(null);
            }
Ejemplo n.º 4
0
            public static EnumContractInfo TryCreate(IEnum enumType)
            {
                if (enumType != null && enumType.HasAttributeInstance(PredefinedType.FLAGS_ATTRIBUTE_CLASS, false))
                {
                    var numericTypeInfo = CSharpNumericTypeInfo.TryCreate(enumType.GetUnderlyingType());
                    if (numericTypeInfo != null)
                    {
                        Debug.Assert(enumType.EnumMembers != null);

                        return numericTypeInfo.TryCreateEnumFlags(enumType.EnumMembers);
                    }
                }

                return null;
            }
Ejemplo n.º 5
0
        public void HandleWrite(TypeHandlingContext context)
        {
            IEnum enumType = context.Type.GetEnumType();

            if (enumType == null)
            {
                throw new NotSupportedException();
            }

            IType baseType = enumType.GetUnderlyingType();
            IEnumBaseTypeHandler handler =
                TypeHandlers.EnumBaseTypeHandlers.SingleOrDefault(h => h.CanHandle(context.WithType(baseType)));

            if (handler == null)
            {
                throw new NotImplementedException();
            }

            handler.HandleEnumWrite(context.TypeOwner, context.Builder, context.Args);
        }