コード例 #1
0
        // Object graph visualizer: collection support temp disabled (porting to new NRefactory).

        /*
         * /// <summary>
         * /// Creates an expression which, when evaluated, creates a List&lt;T&gt; in the debugee
         * /// filled with contents of IEnumerable&lt;T&gt; from the debugee.
         * /// </summary>
         * /// <param name="iEnumerableVariable">Expression for IEnumerable variable in the debugee.</param>
         * /// <param name="itemType">
         * /// The generic argument of IEnumerable&lt;T&gt; that <paramref name="iEnumerableVariable"/> implements.</param>
         * public static Expression CreateDebugListExpression(Expression iEnumerableVariable, DebugType itemType, out DebugType listType)
         * {
         *      // is using itemType.AppDomain ok?
         *      listType = DebugType.CreateFromType(itemType.AppDomain, typeof(System.Collections.Generic.List<>), itemType);
         *      var iEnumerableType = DebugType.CreateFromType(itemType.AppDomain, typeof(IEnumerable<>), itemType);
         *      // explicitely cast the variable to IEnumerable<T>, where T is itemType
         *      Expression iEnumerableVariableExplicitCast = new CastExpression(iEnumerableType.GetTypeReference() , iEnumerableVariable, CastType.Cast);
         *      return new ObjectCreateExpression(listType.GetTypeReference(), iEnumerableVariableExplicitCast.SingleItemList());
         * }*/

        /// <summary>
        /// Evaluates 'new List&lt;T&gt;(iEnumerableValue)' in the debuggee.
        /// </summary>
        public static Value CreateListFromIEnumerable(Value iEnumerableValue)
        {
            ParameterizedType iEnumerableType;
            IType             itemType;

            if (!iEnumerableValue.Type.ResolveIEnumerableImplementation(out iEnumerableType, out itemType))
            {
                throw new GetValueException("Value is not IEnumerable");
            }
            return(ValueNode.CreateListFromIEnumerable(iEnumerableType, iEnumerableValue).GetPermanentReferenceOfHeapValue());
        }