Example #1
0
        public static Array ArrayAdd(Array arr, object value)
        {
            if (arr == null)
            {
                return(null);
            }
            Type  elementType = arr.GetType().GetElementType();
            Array array       = Array.CreateInstance(elementType, arr.Length + 1);

            arr.CopyTo(array, 0);
            try
            {
                array.SetValue(value, array.Length - 1);
                return(array);
            }
            catch (Exception)
            {
                if (BloxUtil.TryConvert(value, elementType, out value))
                {
                    array.SetValue(value, array.Length - 1);
                    return(array);
                }
                throw new Exception("Expected value type was [" + elementType + "] but the value was of type [" + ((value != null) ? value.GetType() : null) + "]");
            }
        }
Example #2
0
 public static bool IsEqual(object a, object b, bool tryConverted)
 {
     if (a == null && b == null)
     {
         return(true);
     }
     if (a != null && b != null)
     {
         if (object.Equals(a, b))
         {
             return(true);
         }
         UnityEngine.Object x       = a as UnityEngine.Object;
         UnityEngine.Object @object = b as UnityEngine.Object;
         if ((x != (UnityEngine.Object)null || @object != (UnityEngine.Object)null) && x == @object)
         {
             return(true);
         }
         if (tryConverted)
         {
             object objB = null;
             BloxUtil.TryConvert(b, a.GetType(), out objB);
             return(object.Equals(a, objB));
         }
         return(false);
     }
     return(false);
 }
Example #3
0
        protected override object RunBlock()
        {
            object obj   = base.contextBlock.Run();
            Array  array = obj as Array;

            if (array != null)
            {
                int num = 0;
                try
                {
                    num = ((base.paramBlocks[0] != null) ? ((int)base.paramBlocks[0].Run()) : 0);
                }
                catch (Exception e)
                {
                    object value = base.paramBlocks[0].Run();
                    object obj2  = null;
                    if (BloxUtil.TryConvert(value, typeof(int), out obj2))
                    {
                        num = (int)obj2;
                        goto end_IL_003d;
                    }
                    base.LogError("The index is invalid. Expected Integer value.", e);
                    return(null);

                    end_IL_003d :;
                }
                if (array.Length == 0)
                {
                    base.LogError("There are no values in the list.", null);
                    return(null);
                }
                if (num >= 0 && num < array.Length)
                {
                    BloxBlock obj3   = base.paramBlocks[1];
                    object    value2 = (obj3 != null) ? obj3.Run() : null;
                    try
                    {
                        array.SetValue(value2, num);
                        base.contextBlock.UpdateWith(array);
                    }
                    catch (Exception ex)
                    {
                        base.LogError(ex.Message, null);
                    }
                    goto IL_0148;
                }
                base.LogError("The index [" + num + "] is out of range. It should be a value between Array Start:[0] and Array Size:[" + array.Length + "]. Remember that arrays start indexing at 0 and not 1.", null);
                return(null);
            }
            base.LogError("The context must be an Array but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            goto IL_0148;
IL_0148:
            return(null);
        }
Example #4
0
 public static void ListRemove(IList list, object value)
 {
     if (list != null)
     {
         Type type = list.GetType().GetGenericArguments()[0];
         if (value != null && value.GetType() != type)
         {
             BloxUtil.TryConvert(value, type, out value);
         }
         list.Remove(value);
     }
 }
Example #5
0
        protected override object RunBlock()
        {
            object obj  = base.contextBlock.Run();
            IList  list = obj as IList;

            if (list != null)
            {
                int num = 0;
                try
                {
                    num = ((base.paramBlocks[0] != null) ? ((int)base.paramBlocks[0].Run()) : 0);
                }
                catch (Exception e)
                {
                    object value = base.paramBlocks[0].Run();
                    object obj2  = null;
                    if (BloxUtil.TryConvert(value, typeof(int), out obj2))
                    {
                        num = (int)obj2;
                        goto end_IL_003d;
                    }
                    base.LogError("The index is invalid. Expected Integer value.", e);
                    return(null);

                    end_IL_003d :;
                }
                if (list.Count == 0)
                {
                    base.LogError("There are no values in the list.", null);
                    return(null);
                }
                if (num >= 0 && num < list.Count)
                {
                    BloxBlock obj3   = base.paramBlocks[1];
                    object    value2 = (obj3 != null) ? obj3.Run() : null;
                    try
                    {
                        BloxUtil.ListSet(list, value2, num);
                    }
                    catch (Exception ex)
                    {
                        base.LogError(ex.Message, null);
                    }
                    goto IL_013c;
                }
                base.LogError("The index [" + num + "] is out of range. It should be a value between List Start:[0] and List Size:[" + list.Count + "]. Remember that lists start indexing at 0 and not 1.", null);
                return(null);
            }
            base.LogError("The context must be a List but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            goto IL_013c;
IL_013c:
            return(null);
        }
Example #6
0
 public object Invoke(object context, object[] args)
 {
     try
     {
         if (this.mi != null)
         {
             return(this.mi.Invoke(context, args));
         }
         if (this.ci != null)
         {
             return(this.ci.Invoke(args));
         }
     }
     catch (ArgumentException)
     {
         bool            flag       = true;
         ParameterInfo[] parameters = this.GetParameters();
         object[]        array      = new object[parameters.Length];
         for (int i = 0; i < array.Length; i++)
         {
             array[i] = ((i >= args.Length) ? null : args[i]);
             if (array[i] == null)
             {
                 if (!parameters[i].ParameterType.IsAssignableFrom(typeof(Nullable)))
                 {
                     flag = false;
                     break;
                 }
             }
             else if (!BloxUtil.TryConvert(array[i], parameters[i].ParameterType, out array[i]))
             {
                 flag = false;
                 break;
             }
         }
         if (flag)
         {
             if (this.mi != null)
             {
                 return(this.mi.Invoke(context, array));
             }
             if (this.ci == null)
             {
                 goto end_IL_003a;
             }
             return(this.ci.Invoke(array));
         }
         throw new Exception("One or more parameters/field values could not be converted to the correct type(s) expected.");
         end_IL_003a :;
     }
     return(null);
 }
Example #7
0
        public static int ListIndexOf(IList list, object value)
        {
            if (list == null)
            {
                return(-1);
            }
            Type type = list.GetType().GetGenericArguments()[0];

            if (value != null && value.GetType() != type)
            {
                BloxUtil.TryConvert(value, type, out value);
            }
            return(list.IndexOf(value));
        }
Example #8
0
        public static bool ListContains(IList list, object value)
        {
            if (list == null)
            {
                return(false);
            }
            Type type = list.GetType().GetGenericArguments()[0];

            if (value != null && value.GetType() != type)
            {
                BloxUtil.TryConvert(value, type, out value);
            }
            return(list.Contains(value));
        }
Example #9
0
 public static void ListSet(IList list, object value, int index)
 {
     if (list != null)
     {
         try
         {
             list[index] = value;
         }
         catch (Exception)
         {
             Type type = list.GetType().GetGenericArguments()[0];
             if (BloxUtil.TryConvert(value, type, out value))
             {
                 list[index] = value;
                 goto end_IL_000f;
             }
             throw new Exception("Expected value type was [" + type + "] but the value was of type [" + ((value != null) ? value.GetType() : null) + "]");
             end_IL_000f :;
         }
     }
 }
Example #10
0
        public static int ArrayIndexOf(Array arr, object value)
        {
            if (arr == null)
            {
                return(-1);
            }
            Type elementType = arr.GetType().GetElementType();

            if (value != null && value.GetType() != elementType)
            {
                BloxUtil.TryConvert(value, elementType, out value);
            }
            for (int i = 0; i < arr.Length; i++)
            {
                if (BloxUtil.IsEqual(arr.GetValue(i), value, false))
                {
                    return(i);
                }
            }
            return(-1);
        }
Example #11
0
 public static Array ArraySet(Array arr, object value, int index)
 {
     if (arr == null)
     {
         return(null);
     }
     try
     {
         arr.SetValue(value, index);
         return(arr);
     }
     catch (Exception)
     {
         Type elementType = arr.GetType().GetElementType();
         if (BloxUtil.TryConvert(value, elementType, out value))
         {
             arr.SetValue(value, arr.Length - 1);
             return(arr);
         }
         throw new Exception("Expected value type was [" + elementType + "] but the value was of type [" + ((value != null) ? value.GetType() : null) + "]");
     }
 }
Example #12
0
        public static Array ArrayInsert(Array arr, object value, int index)
        {
            if (arr == null)
            {
                return(null);
            }
            Type  elementType = arr.GetType().GetElementType();
            Array array       = Array.CreateInstance(elementType, arr.Length + 1);
            int   num         = 0;

            for (int i = 0; i < array.Length; i++)
            {
                if (i == index)
                {
                    try
                    {
                        array.SetValue(value, i);
                    }
                    catch (Exception)
                    {
                        if (BloxUtil.TryConvert(value, elementType, out value))
                        {
                            array.SetValue(value, array.Length - 1);
                            return(array);
                        }
                        throw new Exception("Expected value type was [" + elementType + "] but the value was of type [" + ((value != null) ? value.GetType() : null) + "]");
                    }
                }
                else
                {
                    array.SetValue(arr.GetValue(num), i);
                    num++;
                }
            }
            return(array);
        }
Example #13
0
        public static float AsFloat(object o)
        {
            float result = 0f;

            try
            {
                result = (float)o;
                return(result);
            }
            catch (Exception ex)
            {
                if (o != null && o.GetType() == typeof(int))
                {
                    result = (float)(int)o;
                    return(result);
                }
                if (!BloxUtil.TryConvert <float>(o, out result))
                {
                    Debug.LogError(ex.Message);
                    return(result);
                }
                return(result);
            }
        }