internal static object EnumerateUDT(ValueType oStruct, IRecordEnum intfRecEnum, bool fGet)
 {
     Type typ = oStruct.GetType();
     if ((Information.VarTypeFromComType(typ) != VariantType.UserDefinedType) || typ.IsPrimitive)
     {
         throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "oStruct" }));
     }
     FieldInfo[] fields = typ.GetFields(BindingFlags.Public | BindingFlags.Instance);
     int num2 = 0;
     int num4 = fields.GetUpperBound(0);
     for (int i = num2; i <= num4; i++)
     {
         FieldInfo fieldInfo = fields[i];
         Type fieldType = fieldInfo.FieldType;
         object obj3 = fieldInfo.GetValue(oStruct);
         if (Information.VarTypeFromComType(fieldType) == VariantType.UserDefinedType)
         {
             if (fieldType.IsPrimitive)
             {
                 throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", new string[] { fieldInfo.Name, fieldType.Name })), 5);
             }
             EnumerateUDT((ValueType) obj3, intfRecEnum, fGet);
         }
         else
         {
             intfRecEnum.Callback(fieldInfo, ref obj3);
         }
         if (fGet)
         {
             fieldInfo.SetValue(oStruct, obj3);
         }
     }
     return null;
 }
示例#2
0
        internal static int GetRecordLength(object o, int PackSize = -1)
        {
            if (o == null)
            {
                return(0);
            }
            StructUtils.StructByteLengthHandler byteLengthHandler = new StructUtils.StructByteLengthHandler(PackSize);
            IRecordEnum intfRecEnum = (IRecordEnum)byteLengthHandler;

            if (intfRecEnum == null)
            {
                throw ExceptionUtils.VbMakeException(5);
            }
            StructUtils.EnumerateUDT((ValueType)o, intfRecEnum, false);
            return(byteLengthHandler.Length);
        }
示例#3
0
        internal static object EnumerateUDT(ValueType oStruct, IRecordEnum intfRecEnum, bool fGet)
        {
            Type type = oStruct.GetType();

            if (Information.VarTypeFromComType(type) != VariantType.UserDefinedType || type.IsPrimitive)
            {
                throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[1]
                {
                    nameof(oStruct)
                }));
            }
            FieldInfo[] fields     = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
            int         num1       = 0;
            int         upperBound = fields.GetUpperBound(0);
            int         num2       = num1;
            int         num3       = upperBound;
            int         index      = num2;

            while (index <= num3)
            {
                FieldInfo FieldInfo = fields[index];
                Type      fieldType = FieldInfo.FieldType;
                object    obj       = FieldInfo.GetValue((object)oStruct);
                if (Information.VarTypeFromComType(fieldType) == VariantType.UserDefinedType)
                {
                    if (fieldType.IsPrimitive)
                    {
                        throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", FieldInfo.Name, fieldType.Name)), 5);
                    }
                    StructUtils.EnumerateUDT((ValueType)obj, intfRecEnum, fGet);
                }
                else
                {
                    intfRecEnum.Callback(FieldInfo, ref obj);
                }
                if (fGet)
                {
                    FieldInfo.SetValue((object)oStruct, obj);
                }
                checked { ++index; }
            }
            return((object)null);
        }
示例#4
0
        internal static object EnumerateUDT(ValueType oStruct, IRecordEnum intfRecEnum, bool fGet)
        {
            Type typ = oStruct.GetType();

            if ((Information.VarTypeFromComType(typ) != VariantType.UserDefinedType) || typ.IsPrimitive)
            {
                throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "oStruct" }));
            }
            FieldInfo[] fields = typ.GetFields(BindingFlags.Public | BindingFlags.Instance);
            int         num2   = 0;
            int         num4   = fields.GetUpperBound(0);

            for (int i = num2; i <= num4; i++)
            {
                FieldInfo fieldInfo = fields[i];
                Type      fieldType = fieldInfo.FieldType;
                object    obj3      = fieldInfo.GetValue(oStruct);
                if (Information.VarTypeFromComType(fieldType) == VariantType.UserDefinedType)
                {
                    if (fieldType.IsPrimitive)
                    {
                        throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", new string[] { fieldInfo.Name, fieldType.Name })), 5);
                    }
                    EnumerateUDT((ValueType)obj3, intfRecEnum, fGet);
                }
                else
                {
                    intfRecEnum.Callback(fieldInfo, ref obj3);
                }
                if (fGet)
                {
                    fieldInfo.SetValue(oStruct, obj3);
                }
            }
            return(null);
        }