Пример #1
0
 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));
 }
Пример #2
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];
     }
 }
Пример #3
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;
                     }
                 }
             }
         }
     }
 }