Giter Site home page Giter Site logo

expressive's Introduction

About

Expressive is a library that converts method IL into expression trees.
Or, at least, it attempts to, since not all methods can be converted into a single expression.

Example:

public string FullName {
    get { return this.FirstName + " " + this.LastName; }
}

is converted to

x => string.Concat(x.FirstName, " ", x.LastName)

Use

NuGet Package: http://nuget.org/List/Packages/Expressive
API Docs: https://github.com/ashmind/expressive/wiki/External-API

Reason

There are situations (mostly LINQ-related) when there is a large difference between use of a simple (for example, DB-mapped) property and a calculated property that contains some business/domain logic. Above example is the most classical one, but there are a lot more.

These cases can be solved using things like HqlGeneratorForProperty in NHibernate and rewriters/visitors in other frameworks, but this requires logic/effort duplication, and such logic has to be maintained in both places.

Expressive allows you to reuse the code directly. In addition to queries, other benefits of such reuse can be, for example, automatic generation of formula columns or transfer of logic between compiled C# and JavaScript.

Issues

All code that uses Expressive should be used in combination with integration tests since significant changes to methods may render them 'inexpressible' (there are some cases when statements can be reduced to expressions, but these cases are rather limited). One rather annoying breaking case is IL instrumentation by, for example, Visual Studio Profiler.

Status

What already works:

  1. Fields/Properties
  2. Methods
  3. Operators
  4. Lambdas
  5. Object initializers (only one level deep)
  6. Simple if that can be expressed as ?:

What does not work:

  1. Array item access
  2. Deep object initializers
  3. Statements

Note: it is completely possible to allow .NET 4.0 "statement expressions" in the results by changing the default Pipeline and replacing a Decompiler.

expressive's People

Contributors

ashmind 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.