Esempio n. 1
0
        static CorValueResult?GetDecimalResult(CorValue value)
        {
            var et = value.ExactType;

            if (et == null || !et.IsSystemDecimal)
            {
                return(null);
            }
            if (value.Size != 16)
            {
                return(null);
            }
            var data = value.ReadGenericValue();

            if (data == null)
            {
                return(null);
            }

            var decimalBits = new int[4];

            decimalBits[3] = BitConverter.ToInt32(data, 0);
            decimalBits[2] = BitConverter.ToInt32(data, 4);
            decimalBits[0] = BitConverter.ToInt32(data, 8);
            decimalBits[1] = BitConverter.ToInt32(data, 12);
            try {
                return(new CorValueResult(new decimal(decimalBits)));
            }
            catch (ArgumentException) {
            }

            return(null);
        }
Esempio n. 2
0
        public CorValue Box(CorValue value)
        {
            Debug.Assert(value != null && value.IsGeneric && !value.IsBox && !value.IsHeap && value.ExactType.IsValueType);
            if (value == null || !value.IsGeneric || value.IsBox || value.IsHeap || !value.ExactType.IsValueType)
            {
                return(value);
            }
            var res = WaitForResult(eval.NewParameterizedObjectNoConstructor(value.ExactType.Class, value.ExactType.TypeParameters.ToArray()));

            if (res == null || res.Value.WasException)
            {
                return(null);
            }
            var newObj = res.Value.ResultOrException;
            var r      = newObj.NeuterCheckDereferencedValue;
            var vb     = r == null ? null : r.BoxedValue;

            if (vb == null)
            {
                return(null);
            }
            int hr = vb.WriteGenericValue(value.ReadGenericValue());

            if (hr < 0)
            {
                return(null);
            }
            return(newObj);
        }
Esempio n. 3
0
        static CorValueResult?GetDateTimeResult(CorValue value)
        {
            var et = value.ExactType;

            if (et == null || !et.IsSystemDateTime)
            {
                return(null);
            }
            if (value.Size != 8)
            {
                return(null);
            }
            var data = value.ReadGenericValue();

            if (data == null)
            {
                return(null);
            }
            if (DateTime_ctor_UInt64 != null)
            {
                return(new CorValueResult(DateTime_ctor_UInt64(BitConverter.ToUInt64(data, 0))));
            }

            return(null);
        }
Esempio n. 4
0
        static CorValueResult?GetSimpleResult(CorValue value, CorElementType etype)
        {
            byte[] data;
            switch (etype)
            {
            case CorElementType.Boolean:
                if (value.Size != 1)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult(data[0] != 0));

            case CorElementType.Char:
                if (value.Size != 2)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult(BitConverter.ToChar(data, 0)));

            case CorElementType.I1:
                if (value.Size != 1)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult((sbyte)data[0]));

            case CorElementType.U1:
                if (value.Size != 1)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult(data[0]));

            case CorElementType.I2:
                if (value.Size != 2)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult(BitConverter.ToInt16(data, 0)));

            case CorElementType.U2:
                if (value.Size != 2)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult(BitConverter.ToUInt16(data, 0)));

            case CorElementType.I4:
                if (value.Size != 4)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult(BitConverter.ToInt32(data, 0)));

            case CorElementType.U4:
                if (value.Size != 4)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult(BitConverter.ToUInt32(data, 0)));

            case CorElementType.I8:
                if (value.Size != 8)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult(BitConverter.ToInt64(data, 0)));

            case CorElementType.U8:
                if (value.Size != 8)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult(BitConverter.ToUInt64(data, 0)));

            case CorElementType.R4:
                if (value.Size != 4)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult(BitConverter.ToSingle(data, 0)));

            case CorElementType.R8:
                if (value.Size != 8)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                return(new CorValueResult(BitConverter.ToDouble(data, 0)));

            case CorElementType.TypedByRef:
                break;                //TODO:

            case CorElementType.I:
                if (value.Size != (uint)Utils.DebuggeeIntPtrSize)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                Debug.Assert(Utils.DebuggeeIntPtrSize == IntPtr.Size, "Invalid IntPtr size");
                if (Utils.DebuggeeIntPtrSize == 4)
                {
                    return(new CorValueResult(new IntPtr(BitConverter.ToInt32(data, 0))));
                }
                return(new CorValueResult(new IntPtr(BitConverter.ToInt64(data, 0))));

            case CorElementType.U:
            case CorElementType.Ptr:
            case CorElementType.FnPtr:
                if (value.Size != (uint)Utils.DebuggeeIntPtrSize)
                {
                    break;
                }
                data = value.ReadGenericValue();
                if (data == null)
                {
                    break;
                }
                Debug.Assert(Utils.DebuggeeIntPtrSize == UIntPtr.Size, "Invalid UIntPtr size");
                if (Utils.DebuggeeIntPtrSize == 4)
                {
                    return(new CorValueResult(new UIntPtr(BitConverter.ToUInt32(data, 0))));
                }
                return(new CorValueResult(new UIntPtr(BitConverter.ToUInt64(data, 0))));

            case CorElementType.Class:
            case CorElementType.ValueType:
                var res = GetDecimalResult(value);
                if (res != null)
                {
                    return(res);
                }
                res = GetNullableResult(value);
                if (res != null)
                {
                    return(res);
                }
                break;
            }

            return(null);
        }