예제 #1
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));
        }
예제 #2
0
 public bool Equals(StructMultiKey <T1, T2> other)
 {
     return(Equals(Value1, other.Value1) && Equals(Value2, other.Value2));
 }