Example #1
0
        public void Setup()
        {
            var members = FastEnum.GetMembers <Fruits>();

            this.Standard          = members.ToDictionary(x => (int)x.Value);
            this.GenericsKeyFrozen = members.ToFrozenDictionary(x => (int)x.Value);
            this.IntKeyFrozen      = members.ToFrozenInt32KeyDictionary(x => (int)x.Value);
        }
Example #2
0
 /// <summary>
 /// Creates instance.
 /// </summary>
 /// <param name="name"></param>
 public EnumMember(String name)
 {
     Value               = Enum.TryParse(name, out T value) ? value : throw new ArgumentException(nameof(name));
     Name                = name;
     FieldInfo           = typeof(T).GetField(name);
     EnumMemberAttribute = FieldInfo?.GetCustomAttribute <EnumMemberAttribute>();
     Labels              = FieldInfo?.GetCustomAttributes <LabelAttribute>().ToFrozenInt32KeyDictionary(x => x.Index, x => x.Value);
 }
Example #3
0
 /// <summary>
 /// Creates instance.
 /// </summary>
 /// <param name="name"></param>
 internal Member(string name)
 {
     this.Value
         = Enum.TryParse <T>(name, out var value)
         ? value
         : throw new ArgumentException(nameof(name));
     this.Name                = name;
     this.FieldInfo           = typeof(T).GetField(name);
     this.EnumMemberAttribute = this.FieldInfo.GetCustomAttribute <EnumMemberAttribute>();
     this.Labels
         = this.FieldInfo
           .GetCustomAttributes <LabelAttribute>()
           .ToFrozenInt32KeyDictionary(x => x.Index, x => x.Value);
 }
 /// <summary>
 /// Converts to <see cref="FrozenInt32KeyDictionary{TValue}"/>.
 /// </summary>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="source"></param>
 /// <param name="keySelector"></param>
 /// <param name="valueSelector"></param>
 /// <returns></returns>
 public static FrozenInt32KeyDictionary <TValue> ToFrozenInt32KeyDictionary <TSource, TValue>(this IEnumerable <TSource> source, Func <TSource, int> keySelector, Func <TSource, TValue> valueSelector)
 => FrozenInt32KeyDictionary <TValue> .Create(source, keySelector, valueSelector);