// // // // // $Revision: 2185 $ // using System; using System.ComponentModel; using Debugger.Wrappers.CorDebug; namespace Debugger { // This part of the class provides support for primitive types // eg int, bool, string public partial class Value { ICorDebugGenericValue CorGenericValue { get { if (!this.Type.IsPrimitive && !this.Type.IsValueType && !this.Type.IsByRef()) throw new DebuggerException("Value is not a 'generic'"); return CorValue.CastTo(); //throw new DebuggerException("Value is not a 'generic'"); } } /// /// Returns true if the value is an primitive type. /// eg int, bool, string /// public bool IsPrimitive { get { return !IsNull && this.Type.IsPrimitive; } } /// Gets a value indicating whether the type is an integer type public bool IsInteger { get { return !IsNull && this.Type.IsInteger; } } /// /// Gets or sets the value of a primitive type. /// /// If setting of a value fails, NotSupportedException is thrown. /// public object PrimitiveValue { get { if (CorType == CorElementType.STRING) { return (CorValue.CastTo()).String; } else { return CorGenericValue.Value; } } set { object newValue; if (!is_cnst) { TypeConverter converter = TypeDescriptor.GetConverter(this.Type.ManagedType); try { newValue = converter.ConvertFrom(value); } catch (System.Exception e){ //throw new System.Exception(e.Message); newValue = value; //else //throw new NotSupportedException("Can not convert " + value.GetType().ToString() + " to " + this.Type.ManagedType.ToString()); } } else newValue = value; if (CorType == CorElementType.STRING) { throw new NotSupportedException(); } else { CorGenericValue.Value = newValue; } this.cache.AsString = value.ToString(); NotifyChange(); } } // ICorDebugGenericValue CorGenericValue { // get { // if (!this.Type.IsPrimitive && !this.Type.IsValueType) throw new DebuggerException("Value is not a 'generic'"); // // // Dereference and unbox // if (this.CorValue.Is()) { // return this.CorValue.CastTo().Dereference().CastTo().Object.CastTo(); // } else { // return this.CorValue.CastTo(); // } // } // } /// /// Gets or sets the value of a primitive type. /// /// If setting of a value fails, NotSupportedException is thrown. /// // public object PrimitiveValue { // get { // if (!this.Type.IsPrimitive) throw new DebuggerException("Value is not a primitive type"); // if (this.Type.IsString) { // if (this.IsNull) return null; // return this.CorValue.CastTo().Dereference().CastTo().String; // } else { // return CorGenericValue.Value; // } // } // set { // if (this.Type.IsString) { // throw new NotImplementedException(); // } else { // if (value == null) { // throw new DebuggerException("Can not set primitive value to null"); // } // object newValue; // try { // newValue = Convert.ChangeType(value, this.Type.ManagedType); // } catch { // throw new NotSupportedException("Can not convert " + value.GetType().ToString() + " to " + this.Type.ManagedType.ToString()); // } // CorGenericValue.Value = newValue; // } // } // } } }