public void Ctor_Int_Int(int upperBound1, int upperBound2, int expectedLength)
        {
            var attribute = new VBFixedArrayAttribute(upperBound1, upperBound2);

            Assert.Equal(new int[] { upperBound1, upperBound2 }, attribute.Bounds);
            Assert.Equal(expectedLength, attribute.Length);
        }
Exemple #2
0
            bool IRecordEnum.Callback(FieldInfo field_info, ref object vValue)
            {
                Type fieldType = field_info.FieldType;

                if (fieldType == null)
                {
                    throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "Empty")), 5);
                }
                if (fieldType.IsArray)
                {
                    object[] customAttributes = field_info.GetCustomAttributes(typeof(VBFixedArrayAttribute), false);
                    VBFixedArrayAttribute fixedArrayAttribute = customAttributes == null || customAttributes.Length == 0 ? (VBFixedArrayAttribute)null : (VBFixedArrayAttribute)customAttributes[0];
                    Type elementType = fieldType.GetElementType();
                    int  num         = 0;
                    int  size        = 0;
                    int  align       = 0;
                    if (fixedArrayAttribute == null)
                    {
                        num  = 1;
                        size = 4;
                    }
                    else
                    {
                        num = fixedArrayAttribute.Length;
                        this.GetFieldSize(field_info, elementType, ref align, ref size);
                    }
                    this.SetAlignment(align);
                    checked { this.m_StructLength += num * size; }
                    return(false);
                }
                int align1 = 0;
                int size1  = 0;

                this.GetFieldSize(field_info, fieldType, ref align1, ref size1);
                this.SetAlignment(align1);
                checked { this.m_StructLength += size1; }
                return(false);
            }
Exemple #3
0
        public bool Callback(FieldInfo field_info, ref object vValue)
        {
            Type fieldType = field_info.FieldType;

            if (fieldType == null)
            {
                throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "Empty")), 5);
            }
            if (fieldType.IsArray)
            {
                object[] customAttributes1 = field_info.GetCustomAttributes(typeof(VBFixedArrayAttribute), false);
                Array    arr = (Array)null;
                int      FixedStringLength = -1;
                object[] customAttributes2 = field_info.GetCustomAttributes(typeof(VBFixedStringAttribute), false);
                if (customAttributes2 != null && customAttributes2.Length > 0)
                {
                    VBFixedStringAttribute fixedStringAttribute = (VBFixedStringAttribute)customAttributes2[0];
                    if (fixedStringAttribute.Length > 0)
                    {
                        FixedStringLength = fixedStringAttribute.Length;
                    }
                }
                if (customAttributes1 == null || customAttributes1.Length == 0)
                {
                    this.m_oFile.GetDynamicArray(ref arr, fieldType.GetElementType(), FixedStringLength);
                }
                else
                {
                    VBFixedArrayAttribute fixedArrayAttribute = (VBFixedArrayAttribute)customAttributes1[0];
                    int firstBound  = fixedArrayAttribute.FirstBound;
                    int secondBound = fixedArrayAttribute.SecondBound;
                    arr = (Array)vValue;
                    this.m_oFile.GetFixedArray(0L, ref arr, fieldType.GetElementType(), firstBound, secondBound, FixedStringLength);
                }
                vValue = (object)arr;
            }
            else
            {
                switch (Type.GetTypeCode(fieldType))
                {
                case TypeCode.DBNull:
                    throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "DBNull")), 5);

                case TypeCode.Boolean:
                    vValue = (object)this.m_oFile.GetBoolean(0L);
                    break;

                case TypeCode.Char:
                    vValue = (object)this.m_oFile.GetChar(0L);
                    break;

                case TypeCode.Byte:
                    vValue = (object)this.m_oFile.GetByte(0L);
                    break;

                case TypeCode.Int16:
                    vValue = (object)this.m_oFile.GetShort(0L);
                    break;

                case TypeCode.Int32:
                    vValue = (object)this.m_oFile.GetInteger(0L);
                    break;

                case TypeCode.Int64:
                    vValue = (object)this.m_oFile.GetLong(0L);
                    break;

                case TypeCode.Single:
                    vValue = (object)this.m_oFile.GetSingle(0L);
                    break;

                case TypeCode.Double:
                    vValue = (object)this.m_oFile.GetDouble(0L);
                    break;

                case TypeCode.Decimal:
                    vValue = (object)this.m_oFile.GetDecimal(0L);
                    break;

                case TypeCode.DateTime:
                    vValue = (object)this.m_oFile.GetDate(0L);
                    break;

                case TypeCode.String:
                    object[] customAttributes = field_info.GetCustomAttributes(typeof(VBFixedStringAttribute), false);
                    if (customAttributes == null || customAttributes.Length == 0)
                    {
                        vValue = (object)this.m_oFile.GetLengthPrefixedString(0L);
                        break;
                    }
                    int ByteLength = ((VBFixedStringAttribute)customAttributes[0]).Length;
                    if (ByteLength == 0)
                    {
                        ByteLength = -1;
                    }
                    vValue = (object)this.m_oFile.GetFixedLengthString(0L, ByteLength);
                    break;

                default:
                    if (fieldType == typeof(object))
                    {
                        this.m_oFile.GetObject(ref vValue, 0L, true);
                        break;
                    }
                    if (fieldType == typeof(Exception))
                    {
                        throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "Exception")), 5);
                    }
                    if (fieldType == typeof(Missing))
                    {
                        throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "Missing")), 5);
                    }
                    throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, fieldType.Name)), 5);
                }
            }
            bool flag = false;

            return(flag);
        }
Exemple #4
0
        public bool Callback(FieldInfo field_info, ref object vValue)
        {
            Type fieldType = field_info.FieldType;

            if (fieldType == null)
            {
                throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "Empty")), 5);
            }
            if (fieldType.IsArray)
            {
                int      FixedStringLength = -1;
                object[] customAttributes1 = field_info.GetCustomAttributes(typeof(VBFixedArrayAttribute), false);
                VBFixedArrayAttribute fixedArrayAttribute = customAttributes1 == null || customAttributes1.Length == 0 ? (VBFixedArrayAttribute)null : (VBFixedArrayAttribute)customAttributes1[0];
                Type elementType = fieldType.GetElementType();
                if (elementType == typeof(string))
                {
                    object[] customAttributes2 = field_info.GetCustomAttributes(typeof(VBFixedStringAttribute), false);
                    FixedStringLength = customAttributes2 == null || customAttributes2.Length == 0 ? -1 : ((VBFixedStringAttribute)customAttributes2[0]).Length;
                }
                if (fixedArrayAttribute == null)
                {
                    this.m_oFile.PutDynamicArray(0L, (Array)vValue, false, FixedStringLength);
                }
                else
                {
                    this.m_oFile.PutFixedArray(0L, (Array)vValue, elementType, FixedStringLength, fixedArrayAttribute.FirstBound, fixedArrayAttribute.SecondBound);
                }
            }
            else
            {
                switch (Type.GetTypeCode(fieldType))
                {
                case TypeCode.DBNull:
                    throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "DBNull")), 5);

                case TypeCode.Boolean:
                    this.m_oFile.PutBoolean(0L, BooleanType.FromObject(vValue), false);
                    break;

                case TypeCode.Char:
                    this.m_oFile.PutChar(0L, CharType.FromObject(vValue), false);
                    break;

                case TypeCode.Byte:
                    this.m_oFile.PutByte(0L, ByteType.FromObject(vValue), false);
                    break;

                case TypeCode.Int16:
                    this.m_oFile.PutShort(0L, ShortType.FromObject(vValue), false);
                    break;

                case TypeCode.Int32:
                    this.m_oFile.PutInteger(0L, IntegerType.FromObject(vValue), false);
                    break;

                case TypeCode.Int64:
                    this.m_oFile.PutLong(0L, LongType.FromObject(vValue), false);
                    break;

                case TypeCode.Single:
                    this.m_oFile.PutSingle(0L, SingleType.FromObject(vValue), false);
                    break;

                case TypeCode.Double:
                    this.m_oFile.PutDouble(0L, DoubleType.FromObject(vValue), false);
                    break;

                case TypeCode.Decimal:
                    this.m_oFile.PutDecimal(0L, DecimalType.FromObject(vValue), false);
                    break;

                case TypeCode.DateTime:
                    this.m_oFile.PutDate(0L, DateType.FromObject(vValue), false);
                    break;

                case TypeCode.String:
                    string   s = vValue == null ? (string)null : vValue.ToString();
                    object[] customAttributes = field_info.GetCustomAttributes(typeof(VBFixedStringAttribute), false);
                    if (customAttributes == null || customAttributes.Length == 0)
                    {
                        this.m_oFile.PutStringWithLength(0L, s);
                        break;
                    }
                    int lengthToWrite = ((VBFixedStringAttribute)customAttributes[0]).Length;
                    if (lengthToWrite == 0)
                    {
                        lengthToWrite = -1;
                    }
                    this.m_oFile.PutFixedLengthString(0L, s, lengthToWrite);
                    break;

                default:
                    if (fieldType == typeof(object))
                    {
                        this.m_oFile.PutObject(vValue, 0L, true);
                        break;
                    }
                    if (fieldType == typeof(Exception))
                    {
                        throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "Exception")), 5);
                    }
                    if (fieldType == typeof(Missing))
                    {
                        throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "Missing")), 5);
                    }
                    throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, fieldType.Name)), 5);
                }
            }
            bool flag = false;

            return(flag);
        }
        public bool Callback(FieldInfo field_info, ref object vValue)
        {
            bool flag;
            Type fieldType = field_info.FieldType;

            if (fieldType == null)
            {
                throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", new string[] { field_info.Name, "Empty" })), 5);
            }
            if (fieldType.IsArray)
            {
                object[] customAttributes = field_info.GetCustomAttributes(typeof(VBFixedArrayAttribute), false);
                Array    arr = null;
                int      fixedStringLength = -1;
                object[] objArray2         = field_info.GetCustomAttributes(typeof(VBFixedStringAttribute), false);
                if ((objArray2 != null) && (objArray2.Length > 0))
                {
                    VBFixedStringAttribute attribute = (VBFixedStringAttribute)objArray2[0];
                    if (attribute.Length > 0)
                    {
                        fixedStringLength = attribute.Length;
                    }
                }
                if ((customAttributes == null) || (customAttributes.Length == 0))
                {
                    this.m_oFile.GetDynamicArray(ref arr, fieldType.GetElementType(), fixedStringLength);
                }
                else
                {
                    VBFixedArrayAttribute attribute2 = (VBFixedArrayAttribute)customAttributes[0];
                    int firstBound  = attribute2.FirstBound;
                    int secondBound = attribute2.SecondBound;
                    arr = (Array)vValue;
                    this.m_oFile.GetFixedArray(0L, ref arr, fieldType.GetElementType(), firstBound, secondBound, fixedStringLength);
                }
                vValue = arr;
                return(flag);
            }
            switch (Type.GetTypeCode(fieldType))
            {
            case TypeCode.DBNull:
                throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", new string[] { field_info.Name, "DBNull" })), 5);

            case TypeCode.Boolean:
                vValue = this.m_oFile.GetBoolean(0L);
                return(flag);

            case TypeCode.Char:
                vValue = this.m_oFile.GetChar(0L);
                return(flag);

            case TypeCode.Byte:
                vValue = this.m_oFile.GetByte(0L);
                return(flag);

            case TypeCode.Int16:
                vValue = this.m_oFile.GetShort(0L);
                return(flag);

            case TypeCode.Int32:
                vValue = this.m_oFile.GetInteger(0L);
                return(flag);

            case TypeCode.Int64:
                vValue = this.m_oFile.GetLong(0L);
                return(flag);

            case TypeCode.Single:
                vValue = this.m_oFile.GetSingle(0L);
                return(flag);

            case TypeCode.Double:
                vValue = this.m_oFile.GetDouble(0L);
                return(flag);

            case TypeCode.Decimal:
                vValue = this.m_oFile.GetDecimal(0L);
                return(flag);

            case TypeCode.DateTime:
                vValue = this.m_oFile.GetDate(0L);
                return(flag);

            case TypeCode.String:
            {
                object[] objArray3 = field_info.GetCustomAttributes(typeof(VBFixedStringAttribute), false);
                if ((objArray3 != null) && (objArray3.Length != 0))
                {
                    VBFixedStringAttribute attribute3 = (VBFixedStringAttribute)objArray3[0];
                    int length = attribute3.Length;
                    if (length == 0)
                    {
                        length = -1;
                    }
                    vValue = this.m_oFile.GetFixedLengthString(0L, length);
                    return(flag);
                }
                vValue = this.m_oFile.GetLengthPrefixedString(0L);
                return(flag);
            }
            }
            if (fieldType == typeof(object))
            {
                this.m_oFile.GetObject(ref vValue, 0L, true);
                return(flag);
            }
            if (fieldType == typeof(Exception))
            {
                throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", new string[] { field_info.Name, "Exception" })), 5);
            }
            if (fieldType == typeof(Missing))
            {
                throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", new string[] { field_info.Name, "Missing" })), 5);
            }
            throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", new string[] { field_info.Name, fieldType.Name })), 5);
        }