Beispiel #1
0
    static bool ReadArray(ViIStream IS, FieldInfo field, ref object data)
    {
        object fieldObject = field.GetValue(data);
        int    len         = ViArrayParser.Length(fieldObject);

        for (int idx = 0; idx < len; ++idx)
        {
            object elementObject = ViArrayParser.Object(fieldObject, idx);
            if (elementObject.GetType().Equals(typeof(Int32)))
            {
                Int32 value;
                if (IS.Read(out value) == false)
                {
                    return(false);
                }
                ViArrayParser.SetObject(fieldObject, idx, value);
            }
            else if (elementObject.GetType().Equals(typeof(String)))
            {
                string value;
                if (IS.Read(out value) == false)
                {
                    return(false);
                }
                ViArrayParser.SetObject(fieldObject, idx, elementObject);
            }
            else
            {
                if (Read(IS, elementObject) == false)
                {
                    return(false);
                }
                ViArrayParser.SetObject(fieldObject, idx, elementObject);
            }
        }
        field.SetValue(data, fieldObject);
        return(true);
    }
Beispiel #2
0
 static ViStaticArray()
 {
     ViArrayParser.Register(typeof(ViStaticArray <T>), GetLength);
     ViArrayParser.Register(typeof(ViStaticArray <T>), GetObject);
     ViArrayParser.Register(typeof(ViStaticArray <T>), SetObject);
 }
Beispiel #3
0
 static bool Read(ViStringIStream IS, object obj)
 {
     FieldInfo[] fieldList = ViSealedDataAssisstant.GetFeilds(obj.GetType());
     foreach (FieldInfo field in fieldList)
     {
         if (field.FieldType.Equals(typeof(Int32)))
         {
             if (ReadInt32Field(IS, field, ref obj) == false)
             {
                 return(false);
             }
         }
         else if (field.FieldType.Equals(typeof(String)))
         {
             if (ReadStringField(IS, field, ref obj) == false)
             {
                 return(false);
             }
         }
         else if (field.FieldType.Name.StartsWith("ViMask32"))
         {
             if (ReadStructInt32Field(IS, field, ref obj) == false)
             {
                 return(false);
             }
         }
         else if (field.FieldType.Name.StartsWith("ViEnum32"))
         {
             if (ReadStructInt32Field(IS, field, ref obj) == false)
             {
                 return(false);
             }
         }
         else if (field.FieldType.Name.StartsWith("ViForeignKey32"))
         {
             if (ReadStructInt32Field(IS, field, ref obj) == false)
             {
                 return(false);
             }
         }
         else if (field.FieldType.Name.StartsWith("ViStaticArray"))
         {
             object fieldObject = field.GetValue(obj);
             int    len         = ViArrayParser.Length(fieldObject);
             for (int idx = 0; idx < len; ++idx)
             {
                 object elementObject = ViArrayParser.Object(fieldObject, idx);
                 if (Read(IS, elementObject) == false)
                 {
                     return(false);
                 }
                 field.SetValue(obj, fieldObject);
             }
         }
         else
         {
             object fieldObject = field.GetValue(obj);
             if (Read(IS, fieldObject) == false)
             {
                 return(false);
             }
             field.SetValue(obj, fieldObject);
         }
     }
     return(true);
 }