Exemplo n.º 1
0
        public static object GetEnumValue(IEmitter emitter, IType type, object constantValue)
        {
            var enumMode = Helpers.EnumEmitMode(type);

            if ((emitter.Validator.IsExternalType(type.GetDefinition()) && enumMode == -1) || enumMode == 2)
            {
                return(constantValue);
            }

            if (enumMode >= 3 && enumMode < 7)
            {
                var member = type.GetFields().FirstOrDefault(f => f.ConstantValue != null && f.ConstantValue.Equals(constantValue));

                if (member == null)
                {
                    return(constantValue);
                }

                string enumStringName = member.Name;
                var    attr           = emitter.GetAttribute(member.Attributes, "Bridge.NameAttribute");

                if (attr != null)
                {
                    enumStringName = emitter.GetEntityName(member);
                }
                else
                {
                    switch (enumMode)
                    {
                    case 3:
                        enumStringName = member.Name.Substring(0, 1).ToLower(CultureInfo.InvariantCulture) + member.Name.Substring(1);
                        break;

                    case 4:
                        break;

                    case 5:
                        enumStringName = enumStringName.ToLowerInvariant();
                        break;

                    case 6:
                        enumStringName = enumStringName.ToUpperInvariant();
                        break;
                    }
                }

                return(enumStringName);
            }

            return(constantValue);
        }
Exemplo n.º 2
0
        private static NameRule GetEnumRule(NameSemantic semantic)
        {
            int enumMode = -1;

            if (semantic.Entity is IField && semantic.Entity.DeclaringType.Kind == TypeKind.Enum)
            {
                enumMode          = Helpers.EnumEmitMode(semantic.Entity.DeclaringType);
                semantic.EnumMode = enumMode;
            }

            switch (enumMode)
            {
            case 1:
                if (semantic.Entity.Name.Length > 1 &&
                    semantic.Entity.Name.ToUpperInvariant() == semantic.Entity.Name)
                {
                    return(NameConvertor.DefaultCaseRule);
                }
                return(NameConvertor.LowerCamelCaseRule);

            case 3:
                return(NameConvertor.LowerCamelCaseRule);

            case 2:
            case 4:
            case 7:
                return(NameConvertor.DefaultCaseRule);

            case 5:
            case 8:
                return(NameConvertor.LowerCaseRule);

            case 6:
            case 9:
                return(NameConvertor.UpperCaseRule);
            }

            return(null);
        }
Exemplo n.º 3
0
        public static bool IsNameEnum(IType type)
        {
            var enumEmitMode = Helpers.EnumEmitMode(type);

            return(enumEmitMode == 1 || enumEmitMode > 6);
        }
Exemplo n.º 4
0
        public static bool IsStringNameEnum(IType type)
        {
            var mode = Helpers.EnumEmitMode(type);

            return(mode >= 3 && mode <= 6);
        }
Exemplo n.º 5
0
 public static bool IsValueEnum(IType type)
 {
     return(Helpers.EnumEmitMode(type) == 2);
 }