コード例 #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);
        }
コード例 #2
0
ファイル: JavaExtensions.cs プロジェクト: zzqxztc/SteamTools
        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);
        }
コード例 #3
0
 public static int EnumToInt(this Java.Lang.Enum value)
 {
     return(value.Ordinal());
 }
コード例 #4
0
 internal static TEnum AsEnum <TEnum> (this Java.Lang.Enum jEnum, int offset = 0)
 {
     return((TEnum)Enum.ToObject(typeof(TEnum), jEnum.Ordinal() + offset));
 }