void EvaluateExpression() { evaluated = true; Value val; try { val = expression.Evaluate(WindowsDebugger.DebuggedProcess); } catch (GetValueException e) { error = e; this.Text = e.Message; return; } this.canSetText = val.Type.IsPrimitive; this.expressionType = val.Type; this.Type = val.Type.Name; this.valueIsNull = val.IsNull; // Note that these return enumerators so they are lazy-evaluated if (val.IsNull) { } else if (val.Type.IsPrimitive || val.Type.FullName == typeof(string).FullName) // Must be before IsClass { } else if (val.Type.IsArray) // Must be before IsClass { if (val.ArrayLength > 0) { this.ChildNodes = Utils.LazyGetChildNodesOfArray(this.Expression, val.ArrayDimensions); } } else if (val.Type.IsClass || val.Type.IsValueType) { if (val.Type.FullNameWithoutGenericArguments == typeof(List <>).FullName) { if ((int)val.GetMemberValue("_size").PrimitiveValue > 0) { this.ChildNodes = Utils.LazyGetItemsOfIList(this.expression); } } else { this.ChildNodes = Utils.LazyGetChildNodesOfObject(this.Expression, val.Type); } } else if (val.Type.IsPointer) { Value deRef = val.Dereference(); if (deRef != null) { this.ChildNodes = new ExpressionNode [] { new ExpressionNode(this.IconImage, "*" + this.Name, this.Expression.AppendDereference()) }; } } if (DebuggingOptions.Instance.ICorDebugVisualizerEnabled) { TreeNode info = ICorDebug.GetDebugInfoRoot(val.AppDomain, val.CorValue); this.ChildNodes = Utils.PrependNode(info, this.ChildNodes); } // Do last since it may expire the object if (val.Type.IsInteger) { fullText = FormatInteger(val.PrimitiveValue); } else if (val.Type.IsPointer) { fullText = String.Format("0x{0:X}", val.PointerAddress); } else if ((val.Type.FullName == typeof(string).FullName || val.Type.FullName == typeof(char).FullName) && !val.IsNull) { try { fullText = '"' + Escape(val.InvokeToString()) + '"'; } catch (GetValueException e) { error = e; fullText = e.Message; return; } } else if ((val.Type.IsClass || val.Type.IsValueType) && !val.IsNull) { try { fullText = val.InvokeToString(); } catch (GetValueException e) { error = e; fullText = e.Message; return; } } else { fullText = val.AsString(); } this.Text = (fullText.Length > 256) ? fullText.Substring(0, 256) + "..." : fullText; }
/// <summary> /// Constructor used by the factory method Create() /// </summary> /// <param name="val"></param> /// <exception cref="System.Management.Automation.GetValueException"> /// Can be thrown by InvokeToString() /// </exception> public ValueNode(Value val) { this.expression = val.Expression; canSetText = false; if (val.Type.IsInteger) { canSetText = (val.Expression is LocalVariableIdentifierExpression) || (val.Expression is ParameterIdentifierExpression) || (val.Expression is ArrayIndexerExpression) || (val.Expression is MemberReferenceExpression && ((MemberReferenceExpression)val.Expression).MemberInfo is FieldInfo); } this.Image = IconService.GetBitmap("Icons.16x16." + GetImageName(val)); this.Name = val.Expression.CodeTail; if (DebuggingOptions.Instance.ShowValuesInHexadecimal && val.Type.IsInteger) { fullText = String.Format("0x{0:X}", val.PrimitiveValue); } else if (val.Type.IsPointer) { fullText = String.Format("0x{0:X}", val.PointerAddress); } else { fullText = val.AsString; } if (val.Type != null) { this.Type = val.Type.Name; } else { this.Type = String.Empty; } // Note that these return enumerators so they are lazy-evaluated this.ChildNodes = null; if (val.IsNull) { } else if (val.Type.IsClass || val.Type.IsValueType) { this.ChildNodes = Utils.GetChildNodesOfObject(this.Expression, val.Type); } else if (val.Type.IsArray) { this.ChildNodes = Utils.GetChildNodesOfArray(this.Expression, val.ArrayDimensions); } else if (val.Type.IsPointer) { Value deRef = val.Dereference(); if (deRef != null) { this.ChildNodes = new AbstractNode [] { new ValueNode(deRef) }; } } if (DebuggingOptions.Instance.ICorDebugVisualizerEnabled) { AbstractNode info = ICorDebug.GetDebugInfoRoot(val.Process, val.CorValue); this.ChildNodes = PrependNode(info, this.ChildNodes); } // Do last since it may expire the object if ((val.Type.IsClass || val.Type.IsValueType) && !val.IsNull) { fullText = val.InvokeToString(); } this.Text = (fullText.Length > 256) ? fullText.Substring(0, 256) + "..." : fullText; }