// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Debugger.AddIn.Visualizers.Utils;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Services;
using ICSharpCode.NRefactory.Ast;
namespace Debugger.AddIn.Visualizers.Graph
{
///
/// ObjectProperty used in ObjectGraph. Has TargetNode.
/// Holds an Expression which is evaluated on demand.
/// Evaluating fills properties like Value and IsAtomic, which are empty until evaluation.
///
public class ObjectGraphProperty : ObjectProperty, IEvaluate
{
///
/// Node that this property points to. Can be null. Always null if is true.
///
public ObjectGraphNode TargetNode { get; set; }
///
/// MemberInfo used for obtaining value of this property
///
public MemberInfo MemberInfo { get; set; }
///
/// Has this property been evaluated? (Has Evaluate been called?)
///
public bool IsEvaluated { get; private set; }
public void Evaluate()
{
if (this.Expression == null) throw new DebuggerVisualizerException("Cannot evaluate property with missing Expression");
Value debuggerVal;
try {
debuggerVal = this.Expression.Evaluate(WindowsDebugger.CurrentProcess);
} catch (System.Exception ex) {
this.Value = "Exception: " + ex.Message;
this.IsEvaluated = true;
return;
}
this.IsAtomic = debuggerVal.Type.IsAtomic();
this.IsNull = debuggerVal.IsNull;
// null and complex properties will show empty string
this.Value = debuggerVal.IsNull || (!this.IsAtomic) ? string.Empty : debuggerVal.InvokeToString();
this.IsEvaluated = true;
}
}
}