public static object Deserialize(byte[] data, Type t)
 {
     if (t == null)
     {
         return(null);
     }
     if (((data != null) ? data.Length : 0) != 0)
     {
         if (t.IsEnum)
         {
             return(Enum.ToObject(t, BloxSerializer.ToInt(data)));
         }
         if (t.IsArray)
         {
             return(BloxSerializer.DeserializeArray(data, t));
         }
         if (t.IsGenericType)
         {
             if (t.GetGenericTypeDefinition() == typeof(List <>))
             {
                 return(BloxSerializer.DeserializeList(data, t));
             }
             return(new byte[0]);
         }
         if (BloxSerializer.readers.ContainsKey(t))
         {
             return(BloxSerializer.readers[t](data));
         }
         return(null);
     }
     return(BloxMemberInfo.GetDefaultValue(t));
 }
 public static string SimpleMemberPath(BloxMemberInfo member)
 {
     if (member == null)
     {
         return("");
     }
     return(member.ReflectedType.Name + "." + member.Name);
 }
        public static string EncodeMember(BloxMemberInfo member)
        {
            if (member == null)
            {
                return("");
            }
            string text = "";

            if (member.MemberType == MemberTypes.Field)
            {
                text = "F";
            }
            else if (member.MemberType == MemberTypes.Property)
            {
                text = "P";
            }
            else if (member.MemberType == MemberTypes.Constructor)
            {
                text = "C";
            }
            else if (member.MemberType == MemberTypes.Method)
            {
                text = "M";
            }
            string[] obj = new string[5]
            {
                text,
                null,
                null,
                null,
                null
            };
            char mEMBER_ENCODE_SEPERATOR = BloxMemberInfo.MEMBER_ENCODE_SEPERATOR;

            obj[1] = mEMBER_ENCODE_SEPERATOR.ToString();
            obj[2] = member.ReflectedType.AssemblyQualifiedName;
            mEMBER_ENCODE_SEPERATOR = BloxMemberInfo.MEMBER_ENCODE_SEPERATOR;
            obj[3] = mEMBER_ENCODE_SEPERATOR.ToString();
            obj[4] = member.Name;
            text   = string.Concat(obj);
            ParameterInfo[] parameters = member.GetParameters();
            if (((parameters != null) ? parameters.Length : 0) != 0)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    string str = text;
                    mEMBER_ENCODE_SEPERATOR = BloxMemberInfo.MEMBER_ENCODE_SEPERATOR;
                    text = str + mEMBER_ENCODE_SEPERATOR.ToString() + parameters[i].ParameterType.AssemblyQualifiedName;
                }
            }
            return(text);
        }
Exemple #4
0
 private void InitParamDefaults()
 {
     if (this.mi != null)
     {
         if (this.mi.MemberType == MemberTypes.Field || this.mi.MemberType == MemberTypes.Property)
         {
             if (this.mi.CanSetValue)
             {
                 this._defaultParamVals    = new object[1];
                 this._defaultParamVals[0] = BloxMemberInfo.GetDefaultValue(this.mi.ReturnType);
             }
         }
         else if (this.paramTypes != null)
         {
             this._defaultParamVals = new object[this.paramTypes.Length];
             for (int i = 0; i < this.paramTypes.Length; i++)
             {
                 this._defaultParamVals[i] = BloxMemberInfo.GetDefaultValue(this.paramTypes[i]);
             }
         }
     }
     else
     {
         BloxBlockAttribute[] array = (BloxBlockAttribute[])base.GetType().GetCustomAttributes(typeof(BloxBlockAttribute), false);
         if (((array.Length != 0) ? ((array[0].ParamTypes != null) ? array[0].ParamTypes.Length : 0) : 0) != 0)
         {
             this._defaultParamVals = new object[array[0].ParamTypes.Length];
             for (int j = 0; j < this._defaultParamVals.Length; j++)
             {
                 this._defaultParamVals[j] = BloxMemberInfo.GetDefaultValue(array[0].ParamTypes[j]);
             }
         }
     }
     if (this._defaultParamVals == null)
     {
         this._defaultParamVals = new object[0];
     }
 }
Exemple #5
0
 public void Init()
 {
     if (this.active)
     {
         if (this.blockType == BloxBlockType.Unknown || (this.mi != null && !this.mi.IsValid))
         {
             this.isValid = false;
         }
         else
         {
             if (this.returnValue == null && this.returnType != null && this.returnType != typeof(void))
             {
                 this.returnValue = BloxMemberInfo.GetDefaultValue(this.returnType);
             }
             if (this.owningBlock != null && this.mi != null && (this.mi.MemberType == MemberTypes.Field || this.mi.MemberType == MemberTypes.Property))
             {
                 this.paramBlocks = null;
             }
             BloxMemberInfo obj = this.mi;
             this.contextType = ((obj != null) ? obj.ReflectedType : null);
             if (this.contextBlock != null)
             {
                 this.contextBlock.owningEvent = this.owningEvent;
                 this.contextBlock.owningBlock = this;
                 this.contextBlock.Init();
             }
             BloxMemberInfo  obj2  = this.mi;
             ParameterInfo[] array = (obj2 != null) ? obj2.GetParameters() : null;
             if (((array != null) ? array.Length : 0) != 0)
             {
                 this.paramTypes = new Type[array.Length];
                 for (int i = 0; i < this.paramTypes.Length; i++)
                 {
                     this.paramTypes[i] = array[i].ParameterType;
                     if (this.paramTypes[i].IsByRef)
                     {
                         this.hasReferenceTypes = true;
                         if (this.paramBlocks != null && this.paramBlocks.Length >= i && this.paramBlocks[i] != null && this.paramBlocks[i].GetType() == typeof(Variable_Block))
                         {
                             break;
                         }
                         this.LogError("The Block field [" + array[i].Name + "] expected a Variable Block.", null);
                         return;
                     }
                 }
             }
             else if (this.mi != null && (this.mi.MemberType == MemberTypes.Field || this.mi.MemberType == MemberTypes.Property))
             {
                 this.paramTypes = new Type[1]
                 {
                     this.mi.ReturnType
                 };
             }
             if (((this.paramBlocks != null) ? this.paramBlocks.Length : 0) != 0)
             {
                 this.paramValues = new object[this.paramBlocks.Length];
                 for (int j = 0; j < this.paramBlocks.Length; j++)
                 {
                     if (this.paramBlocks[j] == null)
                     {
                         if (this.paramTypes != null && this.paramTypes.Length > j)
                         {
                             this.paramValues[j] = BloxMemberInfo.GetDefaultValue(this.paramTypes[j]);
                         }
                     }
                     else
                     {
                         this.paramBlocks[j].owningEvent = this.owningEvent;
                         this.paramBlocks[j].owningBlock = this;
                         this.paramBlocks[j].fieldIdx    = j;
                         this.paramBlocks[j].Init();
                     }
                 }
             }
             this.InitBlock();
             if (this.isValid)
             {
                 for (BloxBlock bloxBlock = this.firstChild; bloxBlock != null; bloxBlock = bloxBlock.next)
                 {
                     bloxBlock.parentBlock = this;
                     bloxBlock.owningEvent = this.owningEvent;
                     if (bloxBlock.next != null)
                     {
                         bloxBlock.next.prevBlock = bloxBlock;
                     }
                     bloxBlock.Init();
                     if (bloxBlock.selfOrChildCanYield)
                     {
                         this.selfOrChildCanYield = true;
                     }
                 }
             }
         }
     }
 }
        public static BloxMemberInfo DecodeMember(string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                return(null);
            }
            BindingFlags   bindingAttr = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
            BloxMemberInfo result      = null;

            string[] array = data.Split(BloxMemberInfo.MEMBER_ENCODE_SEPERATOR);
            if (array.Length >= 3)
            {
                Type type = Type.GetType(array[1]);
                if (type == null)
                {
                    return(null);
                }
                if (array[0] == "F")
                {
                    MemberInfo[] array2 = type.FindMembers(MemberTypes.Field, bindingAttr, BloxMemberInfo.FilterMembersByName, array[2]);
                    if (array2.Length == 0)
                    {
                        Debug.LogError("Could not find field [" + array[2] + "] in " + type);
                        return(null);
                    }
                    if (array2.Length > 1)
                    {
                        Debug.LogWarning("More than one field with same name: " + array[2]);
                    }
                    result = new BloxMemberInfo(array2[0], type);
                }
                else if (array[0] == "P")
                {
                    MemberInfo[] array3 = type.FindMembers(MemberTypes.Property, bindingAttr, BloxMemberInfo.FilterMembersByName, array[2]);
                    if (array3.Length == 0)
                    {
                        Debug.LogError("Could not find property [" + array[2] + "] in " + type);
                        return(null);
                    }
                    if (array3.Length > 1)
                    {
                        Debug.LogWarning("More than one property with same name: " + array[2]);
                    }
                    result = new BloxMemberInfo(array3[0], type);
                }
                else if (array[0] == "C")
                {
                    if (string.IsNullOrEmpty(array[2]))
                    {
                        return(new BloxMemberInfo(type, type));
                    }
                    ConstructorInfo[] array4 = (ConstructorInfo[])type.FindMembers(MemberTypes.Constructor, bindingAttr, BloxMemberInfo.FilterMembersByName, array[2]);
                    if (array4.Length == 0)
                    {
                        Debug.LogError("Could not find constructor [" + array[2] + "] in " + type);
                        return(null);
                    }
                    if (array4.Length == 1)
                    {
                        result = new BloxMemberInfo(array4[0], type);
                    }
                    else
                    {
                        Type[] array5 = new Type[0];
                        if (array.Length > 3)
                        {
                            array5 = new Type[array.Length - 3];
                            for (int i = 0; i < array.Length - 3; i++)
                            {
                                array5[i] = Type.GetType(array[i + 3]);
                                if (array5[i] == null)
                                {
                                    Debug.LogError("Could not get parameter type [" + array[i + 3] + "] for " + array[1] + "." + array[2]);
                                    return(null);
                                }
                            }
                        }
                        for (int j = 0; j < array4.Length; j++)
                        {
                            ParameterInfo[] parameters = array4[j].GetParameters();
                            if (array5.Length == parameters.Length)
                            {
                                if (parameters.Length == 0)
                                {
                                    result = new BloxMemberInfo(array4[j], type);
                                    break;
                                }
                                bool flag = true;
                                int  num  = 0;
                                while (num < parameters.Length)
                                {
                                    if (array5[num] == parameters[num].ParameterType)
                                    {
                                        num++;
                                        continue;
                                    }
                                    flag = false;
                                    break;
                                }
                                if (flag)
                                {
                                    result = new BloxMemberInfo(array4[j], type);
                                    break;
                                }
                            }
                        }
                    }
                }
                else if (array[0] == "M")
                {
                    MethodInfo[] array6 = (MethodInfo[])type.FindMembers(MemberTypes.Method, bindingAttr, BloxMemberInfo.FilterMembersByName, array[2]);
                    if (array6.Length == 0)
                    {
                        Debug.LogError("Could not find method [" + array[2] + "] in " + type);
                        return(null);
                    }
                    if (array6.Length == 1)
                    {
                        result = new BloxMemberInfo(array6[0], type);
                    }
                    else
                    {
                        Type[] array7 = new Type[0];
                        if (array.Length > 3)
                        {
                            array7 = new Type[array.Length - 3];
                            for (int k = 0; k < array.Length - 3; k++)
                            {
                                array7[k] = Type.GetType(array[k + 3]);
                                if (array7[k] == null)
                                {
                                    Debug.Log(data);
                                    Debug.LogError("Could not get parameter type [" + array[k + 3] + "] for " + array[1] + " ." + array[2]);
                                    return(null);
                                }
                            }
                        }
                        for (int l = 0; l < array6.Length; l++)
                        {
                            ParameterInfo[] parameters2 = array6[l].GetParameters();
                            if (array7.Length == parameters2.Length)
                            {
                                if (parameters2.Length == 0)
                                {
                                    result = new BloxMemberInfo(array6[l], type);
                                    break;
                                }
                                bool flag2 = true;
                                int  num2  = 0;
                                while (num2 < parameters2.Length)
                                {
                                    if (array7[num2] == parameters2[num2].ParameterType)
                                    {
                                        num2++;
                                        continue;
                                    }
                                    flag2 = false;
                                    break;
                                }
                                if (flag2)
                                {
                                    result = new BloxMemberInfo(array6[l], type);
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    Debug.LogError("[BloxUtil.Create] Unexpected flag: " + array[0]);
                }
            }
            else
            {
                Debug.LogError("[BloxUtil.Create] Invalid data provided");
            }
            return(result);
        }