System.Linq.Expressions.Error.MustRewriteToSameNode C# (CSharp) Method

MustRewriteToSameNode() static private method

InvalidOperationException with message like "When called from '{0}', rewriting a node of type '{1}' must return a non-null value of the same type. Alternatively, override '{2}' and change it to not visit children of this type."
static private MustRewriteToSameNode ( object p0, object p1, object p2 ) : Exception
p0 object
p1 object
p2 object
return System.Exception
        internal static Exception MustRewriteToSameNode(object p0, object p1, object p2)
        {
            return new InvalidOperationException(Strings.MustRewriteToSameNode(p0, p1, p2));
        }
        /// <summary>

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Visits an expression, casting the result back to the original expression type.
        /// </summary>
        /// <typeparam name="T">The type of the expression.</typeparam>
        /// <param name="nodes">The expression to visit.</param>
        /// <param name="callerName">The name of the calling method; used to report to report a better error message.</param>
        /// <returns>The modified expression, if it or any subexpression was modified;
        /// otherwise, returns the original expression.</returns>
        /// <exception cref="InvalidOperationException">The visit method for this node returned a different type.</exception>
        public ReadOnlyCollection <T> VisitAndConvert <T>(ReadOnlyCollection <T> nodes, string?callerName) where T : Expression
        {
            ContractUtils.RequiresNotNull(nodes, nameof(nodes));
            T[]? newNodes = null;
            for (int i = 0, n = nodes.Count; i < n; i++)
            {
                T?node = Visit(nodes[i]) as T;
                if (node == null)
                {
                    throw Error.MustRewriteToSameNode(callerName, typeof(T), callerName);
                }

                if (newNodes != null)
                {
                    newNodes[i] = node;
                }
                else if (!object.ReferenceEquals(node, nodes[i]))
                {
                    newNodes = new T[n];
                    for (int j = 0; j < i; j++)
                    {
                        newNodes[j] = nodes[j];
                    }
                    newNodes[i] = node;
                }
            }
            if (newNodes == null)
            {
                return(nodes);
            }
            return(new TrueReadOnlyCollection <T>(newNodes));
        }
All Usage Examples Of System.Linq.Expressions.Error::MustRewriteToSameNode
Error