Exemple #1
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);
        }
Exemple #2
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);
        }