Giter Site home page Giter Site logo

mono.linq.expressions's Introduction

Mono.Linq.Expressions

Mono.Linq.Expressions is an helper library to complement the System.Linq.Expressions namespace.

It works on both Mono >= 2.8 and .net >= 4.0.

API


public static class CSharp {
	public string ToCSharpCode (Expression) {}
}

Returns a string containing the C# representation of the expression.


public static class FluentExtensions {}

Provides extension methods to ease the creation of expression trees. For instance, instead of writing:

var field = Expression.Field (
	Expression.Convert (parameter, typeof (string)),
	"Length");

You can write:

var field = parameter.Convert (typeof (string)).Field ("Length");

public abstract class CustomExpression {
	public abstract Expression Accept (CustomExpressionVisitor visitor) {}
}

Base class for custom expressions. Accept takes a custom visitor which extends the built-in ExpressionVisitor with support for custom expressions.


public static class CombineExtensions {
	public static Expression<T> Combine<T> (
		this Expression<T> self,
		Func<Expression, Expression> combinator) where T : Delegate {}

	public static Expression<T> Combine<T> (
		this Expression<T> self,
		Expression<T> expression,
		Func<Expression, Expression, Expression> combinator) where T : Delegate {}
}

Helper to combine a fully created lambda with another into a brand new lambda. This is done by rewriting and inlining the bodies in the resulting lamba. With this, combining two predicates with a And expression or negating an expression can be simply written:

public static Expression<Func<T, bool>> AndAlso<T> (
	this Expression<Func<T, bool>> self,
	Expression<Func<T, bool>> expression)
{
	return self.Combine (expression, Expression.AndAlso);
}

public static Expression<Func<T, bool>> Not<T> (
	this Expression<Func<T, bool>> self)
{
	return self.Combine (Expression.Not);
}

public abstract class ExpressionWriter {}

Provides a base class for pretty print specific language, such as CSharpWriter used by CSharp.ToCSharpCode().


public class DoWhileExpression : CustomExpression {}

A do {} while (condition); statement.


public class ForEachExpression : CustomExpression {}

A foreach (var item in iterable) {} statement.


public class ForExpression : CustomExpression {}

A for (initializer; condition; increment) {} statement.


public class UsingExpression : CustomExpression {}

A using (disposable) {} statement.


public class WhileExpression : CustomExpression {}

A while (condition) {} statement.


public static class PredicateBuilder {

	public static Expression<Func<T, bool>> OrElse<T> (
		this Expression<Func<T, bool>> self,
		Expression<Func<T, bool>> expression) {}

	public static Expression<Func<T, bool>> AndAlso<T> (
		this Expression<Func<T, bool>> self,
		Expression<Func<T, bool>> expression) {}

	public static Expression<Func<T, bool>> Not<T> (
		this Expression<Func<T, bool>> self) {}
}

Provides a way to combine lambda predicates using boolean operators. Expressions are rewritten to keep the predicates simple and understandable by LINQ providers. For instance:

Expression<Func<User, bool>> isOver18 = u => u.Age > 18;
Expression<Func<User, bool>> isFemale = u => u.Gender == Gender.Female;

Expression<Func<User, bool>> femalesOver18 = isOver18.AndAlso (isFemale);

// >> femalesOver18.ToString ()
// u => u.Age > 18 && u.Gender == Gender.Female

mono.linq.expressions's People

Contributors

dammejed avatar frblondin avatar jbevain avatar jonpryor avatar mstrobel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.