private List <ObjectGraphProperty> createProperties(GraphExpression expression, IEnumerable <IMember> members)
        {
            List <ObjectGraphProperty> propertyList = new List <ObjectGraphProperty>();

            foreach (IMember member in members)
            {
                /*if (member.Name.Contains("<")) {
                 *      // skip backing fields
                 *      continue;
                 * }*/
                // ObjectGraphProperty needs string representation to know whether it is expanded
                var propExpression = new GraphExpression(
                    expression.Expr + "." + member.Name,
                    () => expression.GetValue().GetMemberValue(WindowsDebugger.EvalThread, member)
                    );
                // Value, IsAtomic are lazy evaluated
                propertyList.Add(new ObjectGraphProperty
                {
                    Name       = member.Name,
                    Expression = propExpression, Value = "",
                    MemberInfo = member, IsAtomic = true, TargetNode = null
                });
            }
            return(propertyList.Sorted(ObjectPropertyComparer.Instance));
        }
        /// <summary>
        /// Creates new node for the value.
        /// </summary>
        /// <param name="permanentReference">Value, has to be valid.</param>
        /// <returns>New empty object node representing the value.</returns>
        private ObjectGraphNode createNewNode(Value permanentReference, GraphExpression expression)
        {
            if (permanentReference == null)
            {
                throw new ArgumentNullException("permanentReference");
            }

            ObjectGraphNode newNode = new ObjectGraphNode();

            if (permanentReference.Type != null)
            {
                newNode.TypeName = permanentReference.Type.FormatNameCSharp();
            }
            newNode.HashCode = permanentReference.InvokeDefaultGetHashCode();

            resultGraph.AddNode(newNode);
            // remember this node's hashcode for quick lookup
            objectNodesForHashCode.Add(newNode.HashCode, newNode);

            // permanent reference to the object this node represents is useful for graph building,
            // and matching nodes in animations
            newNode.PermanentReference = permanentReference;
            newNode.Expression         = expression;

            return(newNode);
        }
        // Object graph visualizer: collection support temp disabled (porting to new NRefactory).

        /*void LoadNodeCollectionContent(AbstractNode node, GraphExpression thisObject, DebugType iListType)
         * {
         *      var thisObjectAsIList = new GraphExpression(thisObject.Expr.CastToIList(), thisObject.GetValue);
         *      int listCount = thisObjectAsIList.GetValue().GetIListCount();
         *      PropertyInfo indexerProp = iListType.GetProperty("Item");
         *
         *      var v = new List<String>();
         *
         *      for (int i = 0; i < listCount; i++)	{
         *              var itemExpr = new GraphExpression(
         *                      thisObjectAsIList.Expr.AppendIndexer(i),
         *                      () => thisObjectAsIList.GetValue().GetIListItem(i)  // EXPR-EVAL, Does a 'cast' to IList
         *              );
         *              PropertyNode itemNode = new PropertyNode(
         *                      new ObjectGraphProperty { Name = "[" + i + "]", MemberInfo = indexerProp, Expression = itemExpr, Value = "", IsAtomic = true, TargetNode = null });
         *              node.AddChild(itemNode);
         *      }
         * }*/

        void LoadNodeObjectContent(AbstractNode node, GraphExpression expression, IType type)
        {
            // base
            var baseType = type.DirectBaseTypes.FirstOrDefault();

            if (baseType != null)
            {
                var baseClassNode = new BaseClassNode(baseType.FullName, baseType.Name);
                node.AddChild(baseClassNode);
                LoadNodeObjectContent(baseClassNode, expression, baseType);
            }

            var members = type.GetFieldsAndNonIndexedProperties(GetMemberOptions.IgnoreInheritedMembers).
                          Where(m => !m.IsStatic && !m.IsSynthetic && !m.Name.EndsWith(">k__BackingField")).
                          ToList();
            // non-public members
            var nonPublicProperties = createProperties(expression, members.Where(m => !m.IsPublic));

            if (nonPublicProperties.Count > 0)
            {
                var nonPublicMembersNode = new NonPublicMembersNode();
                node.AddChild(nonPublicMembersNode);
                foreach (var nonPublicProperty in nonPublicProperties)
                {
                    nonPublicMembersNode.AddChild(new PropertyNode(nonPublicProperty));
                }
            }

            // public members
            foreach (var property in createProperties(expression, members.Where(m => m.IsPublic)))
            {
                node.AddChild(new PropertyNode(property));
            }
        }
 private ObjectGraph buildGraphForValue(Value rootValue, GraphExpression rootExpression, ExpandedExpressions expandedNodes)
 {
     resultGraph = new ObjectGraph();
     //resultGraph.Root = buildGraphRecursive(debuggerService.GetValueFromName(expression).GetPermanentReference(), expandedNodes);
     resultGraph.Root = createNewNode(rootValue, rootExpression);
     loadContent(resultGraph.Root);
     loadNeighborsRecursive(resultGraph.Root, expandedNodes);
     return(resultGraph);
 }
예제 #5
0
		/// <summary>
		/// Builds full object graph for given string expression.
		/// </summary>
		/// <param name="expression">Expression valid in the program being debugged (eg. variable name)</param>
		/// <returns>Object graph</returns>
		public ObjectGraph BuildGraphForExpression(GraphExpression expression, ExpandedExpressions expandedNodes)
		{
			if (WindowsDebugger.CurrentStackFrame == null) {
				throw new DebuggerVisualizerException("Please use the visualizer when debugging.");
			}
			
			Value rootValue = expression.GetValue();
			if (rootValue.IsNull) {
				throw new DebuggerVisualizerException(expression + " is null.");
			}
			return buildGraphForValue(rootValue.GetPermanentReference(WindowsDebugger.EvalThread), expression, expandedNodes);
		}
        /// <summary>
        /// Returns node in the graph that represents given value, or returns new node if not found.
        /// </summary>
        /// <param name="value">Value for which to obtain the node/</param>
        /// <param name="createdNew">True if new node was created, false if existing node was returned.</param>
        public ObjectGraphNode ObtainNodeForValue(Value value, GraphExpression expression, out bool createdNew)
        {
            createdNew = false;
            ObjectGraphNode nodeForValue = getExistingNodeForValue(value);

            if (nodeForValue == null)
            {
                // if no node for memberValue exists, create it
                nodeForValue = createNewNode(value, expression);
                loadContent(nodeForValue);
                createdNew = true;
            }
            return(nodeForValue);
        }
        /// <summary>
        /// Builds full object graph for given string expression.
        /// </summary>
        /// <param name="expression">Expression valid in the program being debugged (eg. variable name)</param>
        /// <returns>Object graph</returns>
        public ObjectGraph BuildGraphForExpression(GraphExpression expression, ExpandedExpressions expandedNodes)
        {
            if (WindowsDebugger.CurrentStackFrame == null)
            {
                throw new DebuggerVisualizerException("Please use the visualizer when debugging.");
            }

            Value rootValue = expression.GetValue();

            if (rootValue.IsNull)
            {
                throw new DebuggerVisualizerException(expression + " is null.");
            }
            return(buildGraphForValue(rootValue.GetPermanentReference(WindowsDebugger.EvalThread), expression, expandedNodes));
        }
 public ObjectGraphNode ObtainNodeForExpression(GraphExpression expr, out bool createdNewNode)
 {
     return(ObtainNodeForValue(expr.GetValue().GetPermanentReference(WindowsDebugger.EvalThread), expr, out createdNewNode));
 }
        public ObjectGraphNode ObtainNodeForExpression(GraphExpression expr)
        {
            bool createdNewNode;             // ignored (caller is not interested, otherwise he would use the other overload)

            return(ObtainNodeForExpression(expr, out createdNewNode));
        }
예제 #10
0
		/// <summary>
		/// Creates new node for the value.
		/// </summary>
		/// <param name="permanentReference">Value, has to be valid.</param>
		/// <returns>New empty object node representing the value.</returns>
		private ObjectGraphNode createNewNode(Value permanentReference, GraphExpression expression)
		{
			if (permanentReference == null)	throw new ArgumentNullException("permanentReference");
			
			ObjectGraphNode newNode = new ObjectGraphNode();
			if (permanentReference.Type != null) {
				newNode.TypeName = permanentReference.Type.FormatNameCSharp();
			}
			newNode.HashCode = permanentReference.InvokeDefaultGetHashCode();
			
			resultGraph.AddNode(newNode);
			// remember this node's hashcode for quick lookup
			objectNodesForHashCode.Add(newNode.HashCode, newNode);
			
			// permanent reference to the object this node represents is useful for graph building,
			// and matching nodes in animations
			newNode.PermanentReference = permanentReference;
			newNode.Expression = expression;
			
			return newNode;
		}
예제 #11
0
		private List<ObjectGraphProperty> createProperties(GraphExpression expression, IEnumerable<IMember> members)
		{
			List<ObjectGraphProperty> propertyList = new List<ObjectGraphProperty>();
			foreach (IMember member in members) {
				/*if (member.Name.Contains("<")) {
					// skip backing fields
					continue;
				}*/
				// ObjectGraphProperty needs string representation to know whether it is expanded
				var propExpression = new GraphExpression(
					expression.Expr + "." + member.Name,
					() => expression.GetValue().GetMemberValue(WindowsDebugger.EvalThread, member)
				);
				// Value, IsAtomic are lazy evaluated
				propertyList.Add(new ObjectGraphProperty
				                 { Name = member.Name,
				                 	Expression = propExpression, Value = "",
				                 	MemberInfo = member, IsAtomic = true, TargetNode = null });
				
			}
			return propertyList.Sorted(ObjectPropertyComparer.Instance);
		}
예제 #12
0
		// Object graph visualizer: collection support temp disabled (porting to new NRefactory).
		/*void LoadNodeCollectionContent(AbstractNode node, GraphExpression thisObject, DebugType iListType)
		{
			var thisObjectAsIList = new GraphExpression(thisObject.Expr.CastToIList(), thisObject.GetValue);
			int listCount = thisObjectAsIList.GetValue().GetIListCount();
			PropertyInfo indexerProp = iListType.GetProperty("Item");
			
			var v = new List<String>();
			
			for (int i = 0; i < listCount; i++)	{
				var itemExpr = new GraphExpression(
					thisObjectAsIList.Expr.AppendIndexer(i),
					() => thisObjectAsIList.GetValue().GetIListItem(i)  // EXPR-EVAL, Does a 'cast' to IList
				);
				PropertyNode itemNode = new PropertyNode(
					new ObjectGraphProperty { Name = "[" + i + "]", MemberInfo = indexerProp, Expression = itemExpr, Value = "", IsAtomic = true, TargetNode = null });
				node.AddChild(itemNode);
			}
		}*/
		
		void LoadNodeObjectContent(AbstractNode node, GraphExpression expression, IType type)
		{
			// base
			var baseType = type.DirectBaseTypes.FirstOrDefault();
			if (baseType != null) {
				var baseClassNode = new BaseClassNode(baseType.FullName, baseType.Name);
				node.AddChild(baseClassNode);
				LoadNodeObjectContent(baseClassNode, expression, baseType);
			}
			
			var members = type.GetFieldsAndNonIndexedProperties(GetMemberOptions.IgnoreInheritedMembers).
				Where(m => !m.IsStatic && !m.IsSynthetic && !m.Name.EndsWith(">k__BackingField")).
				ToList();
			// non-public members
			var nonPublicProperties = createProperties(expression, members.Where(m => !m.IsPublic));
			if (nonPublicProperties.Count > 0) {
				var nonPublicMembersNode = new NonPublicMembersNode();
				node.AddChild(nonPublicMembersNode);
				foreach (var nonPublicProperty in nonPublicProperties) {
					nonPublicMembersNode.AddChild(new PropertyNode(nonPublicProperty));
				}
			}
			
			// public members
			foreach (var property in createProperties(expression, members.Where(m => m.IsPublic))) {
				node.AddChild(new PropertyNode(property));
			}
		}
예제 #13
0
		/// <summary>
		/// Returns node in the graph that represents given value, or returns new node if not found.
		/// </summary>
		/// <param name="value">Value for which to obtain the node/</param>
		/// <param name="createdNew">True if new node was created, false if existing node was returned.</param>
		public ObjectGraphNode ObtainNodeForValue(Value value, GraphExpression expression, out bool createdNew)
		{
			createdNew = false;
			ObjectGraphNode nodeForValue = getExistingNodeForValue(value);
			if (nodeForValue == null) {
				// if no node for memberValue exists, create it
				nodeForValue = createNewNode(value, expression);
				loadContent(nodeForValue);
				createdNew = true;
			}
			return nodeForValue;
		}
예제 #14
0
		public ObjectGraphNode ObtainNodeForExpression(GraphExpression expr, out bool createdNewNode)
		{
			return ObtainNodeForValue(expr.GetValue().GetPermanentReference(WindowsDebugger.EvalThread), expr, out createdNewNode);
		}
예제 #15
0
		public ObjectGraphNode ObtainNodeForExpression(GraphExpression expr)
		{
			bool createdNewNode; // ignored (caller is not interested, otherwise he would use the other overload)
			return ObtainNodeForExpression(expr, out createdNewNode);
		}
예제 #16
0
		private ObjectGraph buildGraphForValue(Value rootValue, GraphExpression rootExpression, ExpandedExpressions expandedNodes)
		{
			resultGraph = new ObjectGraph();
			//resultGraph.Root = buildGraphRecursive(debuggerService.GetValueFromName(expression).GetPermanentReference(), expandedNodes);
			resultGraph.Root = createNewNode(rootValue, rootExpression);
			loadContent(resultGraph.Root);
			loadNeighborsRecursive(resultGraph.Root, expandedNodes);
			return resultGraph;
		}