Exemple #1
0
        private static object ArrayRecurseDefault(object[] sizes, object def, int sizeindex)
        {
            if (sizes.Length <= sizeindex)
            {
                return(def);
            }

            int size = ExCasts.GetObjectAsInt(ExCasts.UnwrapAtRuntime(sizes[sizeindex]));

            sizeindex++;
            object[] arr = new object[size];
            for (int i = 0; i < size; i++)
            {
                arr[i] = ArrayRecurseDefault(sizes, def, sizeindex);
            }
            return(arr);
        }
Exemple #2
0
 public static object[] Array(object[] args)
 {
     if (args[0] is double)
     {
         args[0] = (int)((double)args[0]);
     }
     if (args[0] is int)
     {
         int      size = (int)args[0];
         object[] arr  = new object[size];
         if (args.Length > 1)
         {
             for (int i = 0; i < size; i++)
             {
                 arr[i] = args[1];
             }
         }
         return(arr);
     }
     else if (args[0] is object[])
     {
         object[] sizes = (object[])args[0];
         int      size  = ExCasts.GetObjectAsInt(ExCasts.UnwrapAtRuntime(sizes[0]));
         object[] arr   = new object[size];
         if (args.Length <= 1)
         {
             for (int i = 0; i < size; i++)
             {
                 arr[i] = ArrayRecurse(sizes, 1);
             }
         }
         else
         {
             for (int i = 0; i < size; i++)
             {
                 arr[i] = ArrayRecurseDefault(sizes, args[1], 1);
             }
         }
         return(arr);
     }
     throw new Exception("Array creation failed because type of sizes was not recognized");
 }