예제 #1
0
파일: ObjectType.cs 프로젝트: ForNeVeR/pnet
        // Bitwise NOT an object.
        public static Object NotObj(Object o)
        {
            Type   enumType;
            Object value;

            switch (CommonType(o, o, out enumType))
            {
            case TypeCode.Boolean:
            {
                return(!BooleanType.FromObject(o));
            }
            break;

            case TypeCode.Byte:
            {
                value = (byte)(~(ByteType.FromObject(o)));
            }
            break;

            case TypeCode.Int16:
            {
                value = (short)(~(ShortType.FromObject(o)));
            }
            break;

            case TypeCode.Int32:
            {
                value = ~(IntegerType.FromObject(o));
            }
            break;

            case TypeCode.Int64:
            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.String:
            case TypeCode.Decimal:
            {
                value = ~(LongType.FromObject(o));
            }
            break;

            default:
            {
                throw new InvalidCastException
                          (S._("VB_InvalidNotArgument"));
            }
                // Not reached.
            }
            if (enumType == null)
            {
                return(value);
            }
            else
            {
                return(Enum.ToObject(enumType, value));
            }
        }
예제 #2
0
파일: ObjectType.cs 프로젝트: ForNeVeR/pnet
        // Shift an object right by an amount.
        public static Object ShiftRightObj(Object o1, int amount)
        {
            switch (GetTypeCode(o1))
            {
            case TypeCode.Boolean:
            {
                return((short)((BooleanType.FromObject(o1) ? -1 : 0) >>
                               (amount & 0x0F)));
            }
            // Not reached.

            case TypeCode.Byte:
            {
                return((byte)(ByteType.FromObject(o1) >>
                              (amount & 0x07)));
            }
            // Not reached.

            case TypeCode.Int16:
            {
                return((short)(ShortType.FromObject(o1) >>
                               (amount & 0x0F)));
            }
            // Not reached.

            case TypeCode.Int32:
            {
                return((int)(IntegerType.FromObject(o1) >>
                             (amount & 0x1F)));
            }
            // Not reached.

            case TypeCode.Int64:
            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.String:
            case TypeCode.Decimal:
            {
                return((long)(LongType.FromObject(o1) >>
                              (amount & 0x3F)));
            }
                // Not reached.
            }
            throw new InvalidCastException
                      (S._("VB_InvalidShiftRightArguments"));
        }
예제 #3
0
파일: ObjectType.cs 프로젝트: ForNeVeR/pnet
        // Integer divide two objects.
        public static Object IDivObj(Object o1, Object o2)
        {
            switch (CommonType(o1, o2, false))
            {
            case TypeCode.Boolean:
            {
                return((short)((BooleanType.FromObject(o1) ? -1 : 0) /
                               (BooleanType.FromObject(o2) ? -1 : 0)));
            }
            // Not reached.

            case TypeCode.Byte:
            {
                return((byte)(ByteType.FromObject(o1) /
                              ByteType.FromObject(o2)));
            }
            // Not reached.

            case TypeCode.Int16:
            {
                return((short)(ShortType.FromObject(o1) /
                               ShortType.FromObject(o2)));
            }
            // Not reached.

            case TypeCode.Int32:
            {
                return((int)(IntegerType.FromObject(o1) /
                             IntegerType.FromObject(o2)));
            }
            // Not reached.

            case TypeCode.Int64:
            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.String:
            case TypeCode.Decimal:
            {
                return((long)(LongType.FromObject(o1) /
                              LongType.FromObject(o2)));
            }
                // Not reached.
            }
            throw new InvalidCastException(S._("VB_InvalidIDivArguments"));
        }
예제 #4
0
 internal override void Input(ref byte Value)
 {
     Value = ByteType.FromObject(this.InputNum(VariantType.Byte));
 }
        internal override void PutObject(object Value, long RecordNumber = 0L, bool ContainedInVariant = true)
        {
            this.ValidateWriteable();
            if (Value == null)
            {
                this.PutEmpty(RecordNumber);
            }
            else
            {
                Type enumType = Value.GetType();
                if (enumType == null)
                {
                    throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedIOType1", new string[] { "Empty" })), 5);
                }
                if (enumType.IsArray)
                {
                    this.PutDynamicArray(RecordNumber, (Array)Value, true, -1);
                }
                else
                {
                    if (enumType.IsEnum)
                    {
                        enumType = Enum.GetUnderlyingType(enumType);
                    }
                    switch (Type.GetTypeCode(enumType))
                    {
                    case TypeCode.DBNull:
                        this.PutShort(RecordNumber, 1, false);
                        return;

                    case TypeCode.Boolean:
                        this.PutBoolean(RecordNumber, BooleanType.FromObject(Value), ContainedInVariant);
                        return;

                    case TypeCode.Char:
                        this.PutChar(RecordNumber, Microsoft.VisualBasic.CompilerServices.CharType.FromObject(Value), ContainedInVariant);
                        return;

                    case TypeCode.Byte:
                        this.PutByte(RecordNumber, ByteType.FromObject(Value), ContainedInVariant);
                        return;

                    case TypeCode.Int16:
                        this.PutShort(RecordNumber, ShortType.FromObject(Value), ContainedInVariant);
                        return;

                    case TypeCode.Int32:
                        this.PutInteger(RecordNumber, IntegerType.FromObject(Value), ContainedInVariant);
                        return;

                    case TypeCode.Int64:
                        this.PutLong(RecordNumber, LongType.FromObject(Value), ContainedInVariant);
                        return;

                    case TypeCode.Single:
                        this.PutSingle(RecordNumber, SingleType.FromObject(Value), ContainedInVariant);
                        return;

                    case TypeCode.Double:
                        this.PutDouble(RecordNumber, DoubleType.FromObject(Value), ContainedInVariant);
                        return;

                    case TypeCode.Decimal:
                        this.PutDecimal(RecordNumber, DecimalType.FromObject(Value), ContainedInVariant);
                        return;

                    case TypeCode.DateTime:
                        this.PutDate(RecordNumber, DateType.FromObject(Value), ContainedInVariant);
                        return;

                    case TypeCode.String:
                        this.PutVariantString(RecordNumber, Value.ToString());
                        return;
                    }
                    if (enumType == typeof(Missing))
                    {
                        throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedIOType1", new string[] { "Missing" })), 5);
                    }
                    if (enumType.IsValueType && !ContainedInVariant)
                    {
                        this.PutRecord(RecordNumber, (ValueType)Value);
                    }
                    else
                    {
                        if (ContainedInVariant && enumType.IsValueType)
                        {
                            throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_PutObjectOfValueType1", new string[] { Utils.VBFriendlyName(enumType, Value) })), 5);
                        }
                        throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedIOType1", new string[] { Utils.VBFriendlyName(enumType, Value) })), 5);
                    }
                }
            }
        }
예제 #6
0
파일: ObjectType.cs 프로젝트: ForNeVeR/pnet
        // Multiply two objects.
        public static Object MulObj(Object o1, Object o2)
        {
            switch (CommonType(o1, o2, false))
            {
            case TypeCode.Boolean:
            {
                return((short)((BooleanType.FromObject(o1) ? -1 : 0) *
                               (BooleanType.FromObject(o2) ? -1 : 0)));
            }
            // Not reached.

            case TypeCode.Byte:
            {
                int bp = ByteType.FromObject(o1) *
                         ByteType.FromObject(o2);
                if (bp <= 255)
                {
                    return((byte)bp);
                }
                else if (bp <= 32767)
                {
                    return((short)bp);
                }
                else
                {
                    return(bp);
                }
            }
            // Not reached.

            case TypeCode.Int16:
            {
                int sp = ShortType.FromObject(o1) *
                         ShortType.FromObject(o2);
                if (sp >= -32768 && sp <= 32767)
                {
                    return((short)sp);
                }
                else
                {
                    return(sp);
                }
            }
            // Not reached.

            case TypeCode.Int32:
            {
                int i1 = IntegerType.FromObject(o1);
                int i2 = IntegerType.FromObject(o2);
                try
                {
                    checked
                    {
                        return(i1 * i2);
                    }
                }
                catch (OverflowException)
                {
                    return(((long)i1) * ((long)i2));
                }
            }
            // Not reached.

            case TypeCode.Int64:
            {
                long l1 = LongType.FromObject(o1);
                long l2 = LongType.FromObject(o2);
                try
                {
                    checked
                    {
                        return(l1 * l2);
                    }
                }
                catch (OverflowException)
                {
                    try
                    {
                        return(((decimal)l1) * ((decimal)l2));
                    }
                    catch (OverflowException)
                    {
                        return(((double)l1) * ((double)l2));
                    }
                }
            }
            // Not reached.

            case TypeCode.Single:
            {
                return(SingleType.FromObject(o1) *
                       SingleType.FromObject(o2));
            }
            // Not reached.

            case TypeCode.Double:
            case TypeCode.String:
            {
                return(DoubleType.FromObject(o1) *
                       DoubleType.FromObject(o2));
            }
            // Not reached.

            case TypeCode.Decimal:
            {
                decimal d1 = DecimalType.FromObject(o1);
                decimal d2 = DecimalType.FromObject(o2);
                try
                {
                    checked
                    {
                        return(d1 * d2);
                    }
                }
                catch (OverflowException)
                {
                    return(((double)d1) * ((double)d2));
                }
            }
                // Not reached.
            }
            throw new InvalidCastException(S._("VB_InvalidMulArguments"));
        }
예제 #7
0
파일: ObjectType.cs 프로젝트: ForNeVeR/pnet
        // Modulus two objects.
        public static Object ModObj(Object o1, Object o2)
        {
            switch (CommonType(o1, o2, false))
            {
            case TypeCode.Boolean:
            {
                return((short)((BooleanType.FromObject(o1) ? -1 : 0) %
                               (BooleanType.FromObject(o2) ? -1 : 0)));
            }
            // Not reached.

            case TypeCode.Byte:
            {
                return((byte)(ByteType.FromObject(o1) %
                              ByteType.FromObject(o2)));
            }
            // Not reached.

            case TypeCode.Int16:
            {
                return((short)(ShortType.FromObject(o1) %
                               ShortType.FromObject(o2)));
            }
            // Not reached.

            case TypeCode.Int32:
            {
                return(IntegerType.FromObject(o1) %
                       IntegerType.FromObject(o2));
            }
            // Not reached.

            case TypeCode.Int64:
            {
                return(LongType.FromObject(o1) %
                       LongType.FromObject(o2));
            }
            // Not reached.

            case TypeCode.Single:
            {
                return(SingleType.FromObject(o1) %
                       SingleType.FromObject(o2));
            }
            // Not reached.

            case TypeCode.Double:
            case TypeCode.String:
            {
                return(DoubleType.FromObject(o1) %
                       DoubleType.FromObject(o2));
            }
            // Not reached.

            case TypeCode.Decimal:
            {
                return(DecimalType.FromObject(o1) %
                       DecimalType.FromObject(o2));
            }
                // Not reached.
            }
            throw new InvalidCastException(S._("VB_InvalidModArguments"));
        }
예제 #8
0
파일: ObjectType.cs 프로젝트: ForNeVeR/pnet
        // Bitwise XOR of two objects.
        public static Object BitXorObj(Object o1, Object o2)
        {
            Type   enumType;
            Object value;

            switch (CommonType(o1, o2, out enumType))
            {
            case TypeCode.Boolean:
            {
                return(((BooleanType.FromObject(o1) ? -1 : 0) ^
                        (BooleanType.FromObject(o2) ? -1 : 0)) != 0);
            }
            break;

            case TypeCode.Byte:
            {
                value = (byte)(ByteType.FromObject(o1) ^
                               ByteType.FromObject(o2));
            }
            break;

            case TypeCode.Int16:
            {
                value = (short)(ShortType.FromObject(o1) ^
                                ShortType.FromObject(o2));
            }
            break;

            case TypeCode.Int32:
            {
                value = (int)(IntegerType.FromObject(o1) ^
                              IntegerType.FromObject(o2));
            }
            break;

            case TypeCode.Int64:
            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.String:
            case TypeCode.Decimal:
            {
                value = (long)(LongType.FromObject(o1) ^
                               LongType.FromObject(o2));
            }
            break;

            default:
            {
                throw new InvalidCastException
                          (S._("VB_InvalidBitXorArguments"));
            }
                // Not reached.
            }
            if (enumType == null)
            {
                return(value);
            }
            else
            {
                return(Enum.ToObject(enumType, value));
            }
        }
예제 #9
0
파일: ObjectType.cs 프로젝트: ForNeVeR/pnet
        // Test two objects and return -1, 0, or 1.
        public static int ObjTst(Object o1, Object o2, bool TextCompare)
        {
            switch (CommonType(o1, o2, true))
            {
            case TypeCode.Boolean:
            {
                int b1 = (BooleanType.FromObject(o1) ? -1 : 0);
                int b2 = (BooleanType.FromObject(o2) ? -1 : 0);
                if (b1 < b2)
                {
                    return(-1);
                }
                else if (b1 > b2)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            // Not reached.

            case TypeCode.Byte:
            {
                byte by1 = ByteType.FromObject(o1);
                byte by2 = ByteType.FromObject(o2);
                if (by1 < by2)
                {
                    return(-1);
                }
                else if (by1 > by2)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            // Not reached.

            case TypeCode.Int16:
            {
                short s1 = ShortType.FromObject(o1);
                short s2 = ShortType.FromObject(o2);
                if (s1 < s2)
                {
                    return(-1);
                }
                else if (s1 > s2)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            // Not reached.

            case TypeCode.Int32:
            {
                int i1 = IntegerType.FromObject(o1);
                int i2 = IntegerType.FromObject(o2);
                if (i1 < i2)
                {
                    return(-1);
                }
                else if (i1 > i2)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            // Not reached.

            case TypeCode.Int64:
            {
                long l1 = LongType.FromObject(o1);
                long l2 = LongType.FromObject(o2);
                if (l1 < l2)
                {
                    return(-1);
                }
                else if (l1 > l2)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            // Not reached.

            case TypeCode.Single:
            {
                float f1 = SingleType.FromObject(o1);
                float f2 = SingleType.FromObject(o2);
                if (f1 < f2)
                {
                    return(-1);
                }
                else if (f1 > f2)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            // Not reached.

            case TypeCode.Double:
            {
                double d1 = DoubleType.FromObject(o1);
                double d2 = DoubleType.FromObject(o2);
                if (d1 < d2)
                {
                    return(-1);
                }
                else if (d1 > d2)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            // Not reached.

            case TypeCode.String:
            {
                if (!TextCompare)
                {
                    return(String.CompareOrdinal
                               (StringType.FromObject(o1),
                               StringType.FromObject(o2)));
                }
                else
                {
                    return(CultureInfo.CurrentCulture.CompareInfo
                           .Compare(StringType.FromObject(o1),
                                    StringType.FromObject(o2),
                                    CompareOptions.IgnoreCase |
                                    CompareOptions.IgnoreKanaType |
                                    CompareOptions.IgnoreWidth));
                }
            }
            // Not reached.

            case TypeCode.Decimal:
            {
                decimal D1 = DecimalType.FromObject(o1);
                decimal D2 = DecimalType.FromObject(o2);
                if (D1 < D2)
                {
                    return(-1);
                }
                else if (D1 > D2)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
                // Not reached.
            }
            throw new InvalidCastException(S._("VB_InvalidTstArguments"));
        }
예제 #10
0
파일: ObjectType.cs 프로젝트: ForNeVeR/pnet
        // Negate an object.
        public static Object NegObj(Object o)
        {
            if (o == null)
            {
                return(0);
            }
            switch (GetTypeCode(o))
            {
            case TypeCode.Boolean:
                return((short)(BooleanType.FromObject(o) ? 1 : 0));

            case TypeCode.Byte:
                return((short)(-(ByteType.FromObject(o))));

            case TypeCode.Int16:
            {
                int svalue = -(ShortType.FromObject(o));
                if (svalue >= -32768 && svalue <= 32767)
                {
                    return((short)svalue);
                }
                else
                {
                    return(svalue);
                }
            }
            // Not reached.

            case TypeCode.Int32:
            {
                int ivalue = IntegerType.FromObject(o);
                if (ivalue != Int32.MinValue)
                {
                    return(-ivalue);
                }
                else
                {
                    return(-((long)ivalue));
                }
            }
            // Not reached.

            case TypeCode.Int64:
            {
                long lvalue = LongType.FromObject(o);
                if (lvalue != Int64.MinValue)
                {
                    return(-lvalue);
                }
                else
                {
                    return(-((decimal)lvalue));
                }
            }
            // Not reached.

            case TypeCode.Single:
                return(-(SingleType.FromObject(o)));

            case TypeCode.Double:
            case TypeCode.String:
                return(-(DoubleType.FromObject(o)));

            case TypeCode.Decimal:
                return(-(DecimalType.FromObject(o)));
            }
            throw new InvalidCastException(S._("VB_InvalidNegArgument"));
        }
        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);
        }