Beispiel #1
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);
        }
        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);
        }
Beispiel #3
0
            private void GetFieldSize(FieldInfo field_info, Type FieldType, ref int align, ref int size)
            {
                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:
                    align = 2;
                    size  = 2;
                    break;

                case TypeCode.Char:
                    align = 2;
                    size  = 2;
                    break;

                case TypeCode.Byte:
                    align = 1;
                    size  = 1;
                    break;

                case TypeCode.Int16:
                    align = 2;
                    size  = 2;
                    break;

                case TypeCode.Int32:
                    align = 4;
                    size  = 4;
                    break;

                case TypeCode.Int64:
                    align = 8;
                    size  = 8;
                    break;

                case TypeCode.Single:
                    align = 4;
                    size  = 4;
                    break;

                case TypeCode.Double:
                    align = 8;
                    size  = 8;
                    break;

                case TypeCode.Decimal:
                    align = 0x10;
                    size  = 0x10;
                    break;

                case TypeCode.DateTime:
                    align = 8;
                    size  = 8;
                    break;

                case TypeCode.String:
                {
                    object[] customAttributes = field_info.GetCustomAttributes(typeof(VBFixedStringAttribute), false);
                    if ((customAttributes != null) && (customAttributes.Length != 0))
                    {
                        VBFixedStringAttribute attribute = (VBFixedStringAttribute)customAttributes[0];
                        int length = attribute.Length;
                        if (length == 0)
                        {
                            length = -1;
                        }
                        size = length;
                        break;
                    }
                    align = 4;
                    size  = 4;
                    break;
                }
                }
                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);
                }
                if (FieldType == typeof(object))
                {
                    throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", new string[] { field_info.Name, "Object" })), 5);
                }
            }
        public bool Callback(FieldInfo field_info, ref object vValue)
        {
            bool   flag;
            string str;
            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)
            {
                VBFixedArrayAttribute attribute;
                int      fixedStringLength = -1;
                object[] objArray          = field_info.GetCustomAttributes(typeof(VBFixedArrayAttribute), false);
                if ((objArray != null) && (objArray.Length != 0))
                {
                    attribute = (VBFixedArrayAttribute)objArray[0];
                }
                else
                {
                    attribute = null;
                }
                Type elementType = fieldType.GetElementType();
                if (elementType == typeof(string))
                {
                    objArray = field_info.GetCustomAttributes(typeof(VBFixedStringAttribute), false);
                    if ((objArray == null) || (objArray.Length == 0))
                    {
                        fixedStringLength = -1;
                    }
                    else
                    {
                        fixedStringLength = ((VBFixedStringAttribute)objArray[0]).Length;
                    }
                }
                if (attribute == null)
                {
                    this.m_oFile.PutDynamicArray(0L, (Array)vValue, false, fixedStringLength);
                    return(flag);
                }
                this.m_oFile.PutFixedArray(0L, (Array)vValue, elementType, fixedStringLength, attribute.FirstBound, attribute.SecondBound);
                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:
                this.m_oFile.PutBoolean(0L, BooleanType.FromObject(vValue), false);
                return(flag);

            case TypeCode.Char:
                this.m_oFile.PutChar(0L, Microsoft.VisualBasic.CompilerServices.CharType.FromObject(vValue), false);
                return(flag);

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

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

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

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

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

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

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

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

            case TypeCode.String:
                if (vValue == null)
                {
                    str = null;
                    break;
                }
                str = vValue.ToString();
                break;

            default:
                if (fieldType == typeof(object))
                {
                    this.m_oFile.PutObject(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);
            }
            object[] customAttributes = field_info.GetCustomAttributes(typeof(VBFixedStringAttribute), false);
            if ((customAttributes == null) || (customAttributes.Length == 0))
            {
                this.m_oFile.PutStringWithLength(0L, str);
                return(flag);
            }
            VBFixedStringAttribute attribute2 = (VBFixedStringAttribute)customAttributes[0];
            int length = attribute2.Length;

            if (length == 0)
            {
                length = -1;
            }
            this.m_oFile.PutFixedLengthString(0L, str, length);
            return(flag);
        }
Beispiel #5
0
        public void Ctor_Int(int length)
        {
            var attribute = new VBFixedStringAttribute(length);

            Assert.Equal(length, attribute.Length);
        }