/// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="values"></param>
 /// <returns></returns>
 public static IEnumerable <IHasID <T> > CreateParameters <T>(IEnumerable <T> values)
 {
     //こいつの存在で
     // CreateValues(HasID.GetValues(Enumerable.Range(1, 9)))
     //に<int>とかなしで類推が効くようになる。
     return(HasID <T> .CreateParameters(values));
 }
 public T GetValue <T>(int index)
 {
     if (-1 < index && index < this.Count)
     {
         return(HasID.GetParameter <T>(values.ElementAt(index)));
     }
     else
     {
         throw new ArgumentOutOfRangeException();
     }
 }
Example #3
0
        static void Main(string[] args)
        {
            //case enum
            var pa1 = HasID.CreateParametersFromEnum <AType>();
            var pa2 = HasID.CreateParametersFromEnum <BType>();
            var pa3 = HasID.CreateParametersFromEnum <CType>();

            var paramsA = Combination.CreateValues(pa1, pa2, pa3);

            foreach (var p in paramsA)
            {
                var ps = new Parameters(p);
                Sample1(ps.GetValue <AType>(0), ps.GetValue <BType>(1), ps.GetValue <CType>(2));
                //var temp = p.ToArray();
                //Sample1(temp[0].GetParameter<AType>(), temp[1].GetParameter<BType>(), temp[2].GetParameter<CType>());
            }
            Console.WriteLine($"paramsA count = {paramsA.Count()}");// 3 * 3 * 5  = 45

            //case int[] part1
            var pb1 = HasID.CreateParameters(Enumerable.Range(5, 10).ToArray());
            var pb2 = HasID.CreateParameters(new int[] { 99, 999, 9999 });

            var paramsB = Combination.CreateValues(pb1, pb2);

            foreach (var p in paramsB)
            {
                var ps = new Parameters(p);
                Sample2(ps.GetValue <int>(0), ps.GetValue <int>(1));
                //var a = p.ToArray();
                //Sample2(a[0].GetParameter<int>(), a[1].GetParameter<int>());
            }
            Console.WriteLine($"paramsB count = {paramsB.Count()}");

            //case int[] part2
            var pc1 = Enumerable.Range(5, 10);
            var pc2 = new int[] { 99, 999, 9999 };

            var paramsC = Combination.CreateValuesFromRaw(pc1, pc2);

            foreach (var p in paramsC)
            {
                var ps = new Parameters(p);
                Sample2(ps.GetValue <int>(0), ps.GetValue <int>(1));
                //var temp = p.ToArray();
                //Sample2(temp[0].GetParameter<int>(), temp[1].GetParameter<int>());
            }
            Console.WriteLine($"paramsC count = {paramsC.Count()}");

            //mix
            var paramsD = Combination.CreateValues(pb1, pb2, pa1, pa2);

            foreach (var p in paramsD)
            {
                var ps = new Parameters(p);
                Sample3(ps.GetValue <int>(0), ps.GetValue <int>(1), ps.GetValue <AType>(2), ps.GetValue <BType>(3));
            }
            Console.WriteLine($"paramsD count = {paramsD.Count()}");


            //
            var paramsE = Combination.CreateValues(pb1, pb2, pa1, pa2);
            var l1      = paramsE.Select(v => new ParametersI(v, 4)).Where(v => v.GetValue <int>(0) * v.GetValue <int>(1) > 1000).ToArray();

            var l2 = paramsE.ToParameters();
            var l3 = paramsE.ToParameters().Where(v => v.GetValue <int>(0) * v.GetValue <int>(1) > 1000).ToArray();

            foreach (var p in l3)
            {
                Console.WriteLine(p);
            }
        }
 /// <summary>
 /// 全部同じ型ならこれでもよい
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="values"></param>
 /// <returns></returns>
 public static IEnumerable <IEnumerable <IHasID> > CreateValuesFromRaw <T>(params IEnumerable <T>[] values)
 {
     return(CreateValuesCore(values.Select(v => HasID <T> .CreateParameters(v)).ToArray()));
 }
 /// <summary>
 /// <para> enum版のfactory enum以外は例外発生</para>
 /// <para> こんな感じで使うHasID.GetEnums<T>() </para>
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static IEnumerable <IHasID <T> > CreateParametersFromEnum <T>()
 {
     return(HasID <T> .CreateParametersFromEnum());
 }