|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Signum.Engine.Linq
{
/// <summary>
/// A visitor that replaces references to one specific instance of a node with another
/// </summary>
internal class Replacer : DbExpressionVisitor
{
Expression searchFor;
Expression replaceWith;
private Replacer() { }
static internal Expression Replace(Expression expression, Expression searchFor, Expression replaceWith)
{
return new Replacer
{
searchFor = searchFor,
replaceWith = replaceWith
}.Visit(expression);
}
protected override Expression Visit(Expression exp)
{
if (exp != null && (exp == this.searchFor || exp.Equals(this.searchFor)))
{
return this.replaceWith;
}
return base.Visit(exp);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.
www.signumframework.com
I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...