Beispiel #1
0
        // Token: 0x06000F4C RID: 3916 RVA: 0x0005AA98 File Offset: 0x00058C98
        private static EnumInfo InitializeValuesAndNames([Nullable(new byte[]
        {
            0,
            1,
            2
        })] StructMultiKey <Type, NamingStrategy> key)
        {
            Type value = key.Value1;

            string[] names  = Enum.GetNames(value);
            string[] array  = new string[names.Length];
            ulong[]  array2 = new ulong[names.Length];
            for (int i = 0; i < names.Length; i++)
            {
                string    text  = names[i];
                FieldInfo field = value.GetField(text, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                array2[i] = EnumUtils.ToUInt64(field.GetValue(null));
                string text2 = (from EnumMemberAttribute a in field.GetCustomAttributes(typeof(EnumMemberAttribute), true)
                                select a.Value).SingleOrDefault <string>();
                bool   hasSpecifiedName = text2 != null;
                string text3            = text2 ?? text;
                if (Array.IndexOf <string>(array, text3, 0, i) != -1)
                {
                    throw new InvalidOperationException("Enum name '{0}' already exists on enum '{1}'.".FormatWith(CultureInfo.InvariantCulture, text3, value.Name));
                }
                array[i] = ((key.Value2 != null) ? key.Value2.GetPropertyName(text3, hasSpecifiedName) : text3);
            }
            return(new EnumInfo(value.IsDefined(typeof(FlagsAttribute), false), array2, names, array));
        }
Beispiel #2
0
        private static Func <object, object> CreateCastConverter([Nullable(new byte[]
        {
            0,
            1,
            1
        })] StructMultiKey <Type, Type> t)
        {
            Type       value  = t.Value1;
            Type       value2 = t.Value2;
            MethodInfo method;

            if ((method = value2.GetMethod("op_Implicit", new Type[]
            {
                value
            })) == null)
            {
                method = value2.GetMethod("op_Explicit", new Type[]
                {
                    value
                });
            }
            MethodInfo methodInfo = method;

            if (methodInfo == null)
            {
                return(null);
            }
            MethodCall <object, object> call = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall <object>(methodInfo);

            return((object o) => call(null, new object[]
            {
                o
            }));
        }
Beispiel #3
0
 public bool Equals(StructMultiKey <T1, T2> other)
 {
     if (!object.Equals(this.Value1, other.Value1))
     {
         return(false);
     }
     return(object.Equals(this.Value2, other.Value2));
 }
Beispiel #4
0
        private static EnumInfo InitializeValuesAndNames(StructMultiKey <Type, NamingStrategy?> key)
        {
            Type enumType = key.Value1;

            string[] names         = Enum.GetNames(enumType);
            string[] resolvedNames = new string[names.Length];
            ulong[]  values        = new ulong[names.Length];
            bool     hasSpecifiedName;

            for (int i = 0; i < names.Length; i++)
            {
                string    name = names[i];
                FieldInfo f    = enumType.GetField(
                    name,
                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static
                    ) !;
                values[i] = ToUInt64(f.GetValue(null));

                string resolvedName;
#if HAVE_DATA_CONTRACTS
                string specifiedName = f.GetCustomAttributes(typeof(EnumMemberAttribute), true)
                                       .Cast <EnumMemberAttribute>()
                                       .Select(a => a.Value)
                                       .SingleOrDefault();
                hasSpecifiedName = specifiedName != null;
                resolvedName     = specifiedName ?? name;

                if (Array.IndexOf(resolvedNames, resolvedName, 0, i) != -1)
                {
                    throw new InvalidOperationException(
                              "Enum name '{0}' already exists on enum '{1}'.".FormatWith(
                                  CultureInfo.InvariantCulture,
                                  resolvedName,
                                  enumType.Name
                                  )
                              );
                }
#else
                resolvedName     = name;
                hasSpecifiedName = false;
#endif

                resolvedNames[i] =
                    key.Value2 != null
                        ? key.Value2.GetPropertyName(resolvedName, hasSpecifiedName)
                        : resolvedName;
            }

            bool isFlags = enumType.IsDefined(typeof(FlagsAttribute), false);

            return(new EnumInfo(isFlags, values, names, resolvedNames));
        }
Beispiel #5
0
        private static Func <object, object> CreateCastConverter(StructMultiKey <Type, Type> t)
        {
            Type       value1 = t.Value1;
            Type       value2 = t.Value2;
            MethodInfo method = value2.GetMethod("op_Implicit", new Type[] { value1 }) ?? value2.GetMethod("op_Explicit", new Type[] { value1 });

            if (method == null)
            {
                return(null);
            }
            MethodCall <object, object> methodCall = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall <object>(method);

            return((object o) => methodCall(null, new object[] { o }));
        }
Beispiel #6
0
        private static EnumInfo InitializeValuesAndNames(StructMultiKey <Type, NamingStrategy> key)
        {
            Type value1 = key.Value1;

            string[] names     = Enum.GetNames(value1);
            string[] strArrays = new string[(int)names.Length];
            ulong[]  num       = new ulong[(int)names.Length];
            for (int i = 0; i < (int)names.Length; i++)
            {
                FieldInfo field = value1.GetField(names[i], BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                num[i] = EnumUtils.ToUInt64(field.GetValue(null));
                string str = (
                    from EnumMemberAttribute a in field.GetCustomAttributes(typeof(EnumMemberAttribute), true)
                    select a.Value).SingleOrDefault <string>() ?? field.Name;
                if (Array.IndexOf <string>(strArrays, str, 0, i) != -1)
                {
                    throw new InvalidOperationException("Enum name '{0}' already exists on enum '{1}'.".FormatWith(CultureInfo.InvariantCulture, str, value1.Name));
                }
                strArrays[i] = (key.Value2 != null ? key.Value2.GetPropertyName(str, false) : str);
            }
            return(new EnumInfo(value1.IsDefined(typeof(FlagsAttribute), false), num, names, strArrays));
        }
Beispiel #7
0
 public bool Equals(StructMultiKey <T1, T2> other)
 {
     return(Equals(Value1, other.Value1) && Equals(Value2, other.Value2));
 }