Ejemplo n.º 1
0
        public static string EnumToString(Java.Lang.Enum <object> e, string format)
        {
            if (string.IsNullOrEmpty(format) ||
                format == "G" || format == "g" ||
                format == "f" || format == "F")
            {
                return(e.ToString());
            }

            var internalEnum = ((object)e) as Enum;

            long val = internalEnum == null ? (long)e.Ordinal() : internalEnum.LongValue();

            if (format == "X")
            {
                return(val.ToString("X8"));
            }
            if (format == "x")
            {
                return(val.ToString("x8"));
            }
            if (format == "d" || format == "D")
            {
                return(val.ToString());
            }

            throw new ArgumentException("invalid format specifier: " + format);
        }
Ejemplo n.º 2
0
        public static string GetJavaEnumName(this JEnum @enum)
        {
            var type     = @enum.GetType();
            var typeName = type.Namespace + Constants.DOT + type.Name;
            var enumName = @enum.Name();

            try
            {
                var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Static);
                foreach (var property in properties)
                {
                    RegisterAttribute?registerAttribute = null;
                    try
                    {
                        registerAttribute = property.GetCustomAttribute <RegisterAttribute>(false);
                    }
                    catch
                    {
                        continue;
                    }
                    if (registerAttribute != null)
                    {
                        if (registerAttribute.Name == enumName)
                        {
                            return(typeName + Constants.DOT + property.Name);
                        }
                    }
                }
            }
            catch
            {
                try
                {
                    var name  = enumName.ToCharArray();
                    var index = Constants.LowerCaseLetters.IndexOf(name[0]);
                    if (index >= 0)
                    {
                        name[0] = Constants.UpperCaseLetters[index];
                        return(typeName + Constants.DOT + new string(name));
                    }
                }
                catch
                {
                }
            }
            return(typeName + Constants.DOT + enumName);
        }
Ejemplo n.º 3
0
 public static int EnumToInt(this Java.Lang.Enum value)
 {
     return(value.Ordinal());
 }
Ejemplo n.º 4
0
 internal static TEnum AsEnum <TEnum> (this Java.Lang.Enum jEnum, int offset = 0)
 {
     return((TEnum)Enum.ToObject(typeof(TEnum), jEnum.Ordinal() + offset));
 }