コード例 #1
0
 public static unsafe void SetRawValue(this ICorDebugGenericValue corGenVal, byte[] value)
 {
     if (corGenVal.GetSize() != value.Length)
     {
         throw new ArgumentException("Incorrect length");
         fixed(byte *pValue = value)
         corGenVal.SetValue(new IntPtr(pValue));
 }
コード例 #2
0
        // Convert the supplied value to the type of this CorGenericValue using System.IConvertable.
        // Then store the value into this CorGenericValue.  Any compatible type can be supplied.
        // For example, if you supply a string and the underlying type is ELEMENT_TYPE_BOOLEAN,
        // Convert.ToBoolean will attempt to match the string against "true" and "false".
        public void SetValue(object value)
        {
            try
            {
                switch (Type)
                {
                case CorElementType.ELEMENT_TYPE_BOOLEAN:
                    bool v = Convert.ToBoolean(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&v));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_I1:
                    SByte sbv = Convert.ToSByte(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&sbv));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_U1:
                    Byte bv = Convert.ToByte(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&bv));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_CHAR:
                    Char cv = Convert.ToChar(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&cv));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_I2:
                    Int16 i16v = Convert.ToInt16(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&i16v));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_U2:
                    UInt16 u16v = Convert.ToUInt16(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&u16v));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_I4:
                    Int32 i32v = Convert.ToInt32(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&i32v));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_U4:
                    UInt32 u32v = Convert.ToUInt32(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&u32v));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_I:
                    Int64 ip64v = Convert.ToInt64(value);
                    var   ipv   = new IntPtr(ip64v);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&ipv));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_U:
                    UInt64 ipu64v = Convert.ToUInt64(value);
                    var    uipv   = new UIntPtr(ipu64v);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&uipv));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_I8:
                    Int64 i64v = Convert.ToInt64(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&i64v));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_U8:
                    UInt64 u64v = Convert.ToUInt64(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&u64v));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_R4:
                    Single sv = Convert.ToSingle(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&sv));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_R8:
                    Double dv = Convert.ToDouble(value);
                    unsafe
                    {
                        SetValueInternal(new IntPtr(&dv));
                    }
                    break;

                case CorElementType.ELEMENT_TYPE_VALUETYPE:
                    var bav = (byte[])value;
                    unsafe
                    {
                        fixed(byte *bufferPtr = &bav[0])
                        {
                            Debug.Assert(Size == bav.Length);
                            m_genVal.SetValue(new IntPtr(bufferPtr));
                        }
                    }
                    break;

                default:
                    throw new InvalidOperationException("Type passed is not recognized.");
                }
            }
            catch (InvalidCastException e)
            {
                throw new InvalidOperationException("Wrong type used for SetValue command", e);
            }
        }