コード例 #1
0
ファイル: Enums.cs プロジェクト: asmodat/AutomatedFx-v1.0
        /// <summary>
        /// This method converts two enum sorurce and destination into one dictionary
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TDestination"></typeparam>
        /// <returns></returns>
        public static Dictionary <TSource, TDestination> ToDictionary <TSource, TDestination>()  where TSource : struct, IConvertible where TDestination : struct, IConvertible
        {
            Dictionary <TSource, TDestination> DictionaryMap = new Dictionary <TSource, TDestination>();

            List <TSource>      SourceList      = Enums.ToList <TSource>();
            List <TDestination> DestinationList = Enums.ToList <TDestination>();

            foreach (TSource key in SourceList)
            {
                TDestination value;
                try
                {
                    value = Enums.ToEnum <TSource, TDestination>(key);
                }
                catch { continue; }

                if (DictionaryMap.ContainsKey(key))
                {
                    throw new Exception("There Can't be to exact values, Key cannot be created !");
                }
                DictionaryMap.Add(key, value);
            }


            return(DictionaryMap);
        }
コード例 #2
0
ファイル: Enums.cs プロジェクト: asmodat/Asmodat-Crypto-Forex
 public static T[] ToArray <T>()
 {
     return(Enums.ToList <T>().ToArray());
 }