|
#pragma once
using namespace System;
using namespace System::Reflection;
using namespace System::Collections::Generic;
namespace EeekSoft {
namespace CLinq {
/// <summary>
/// This template class represents expression. You can use tempalte specializations
/// to simplify working with expressions of specific type.
/// </summary>
template<class T> ref class Expr : ExpressionWrapper<T>
{
public:
/// <summary>
/// Returns type information about the type of this expression
/// </summary>
static property Type^ WrappedType { Type^ get() { return T::typeid; } }
public:
/// <summary>
/// Creates expression representing literal value
/// </summary>
Expr<T>(T val) { _value = gcnew Literal<T>(val); }
/// <summary>
/// Conversion from generic Expression class to Expr template
/// </summary>
Expr<T>(Expression<T>^ value) { _value = value; }
/// <summary>
/// Copy constructor
/// </summary>
Expr<T>(Expr<T>% t) { _value = t._value; }
public:
/// <summary>
/// Invocation of method specified by its name. Returns expression representing the call.
/// </summary>
template<class R> Expr<R> Invoke(String^ name, ... cli::array<GenericExpression^>^ args)
{ return Expr<R>(ExpressionInvoke<R>(name, args)); }
/// <summary>
/// Invocation of static method specified by its name. Returns expression representing the call.
/// </summary>
template<class R> static Expr<R> InvokeStatic(String^ name, ... cli::array<GenericExpression^>^ args)
{ return Expr<R>(ExpressionInvokeStatic<R>(name, args)); }
/// <summary>
/// Reading of a property specified by its name. Returns expression representing the property read.
/// </summary>
template<class R> Expr<R> Prop(String^ name)
{ return Expr<R>(ExpressionProp<R>(name)); }
/// <summary>
/// Reading of a property specified by its name. Returns expression representing the property read.
/// </summary>
template<class R> static Expr<R> PropStatic(String^ name)
{ return Expr<R>(ExpressionPropStatic<R>(name)); }
};
/// <summary>
/// This template class represents variable. You can use tempalte specializations
/// to simplify working with variables of specific type.
/// </summary>
template<class T> ref class Var : ExpressionWrapper<T>
{
public:
Var<T>(String^ name)
{
_value = gcnew Variable<T>(name);
}
operator Expression<T>^()
{
return _value;
}
};
}
}
|
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 live in Prague, the capital city of Czech republic (most of the time
). I've been very interested in functional programming recently and I have a passion for the new Microsoft F# language. I'm writing a book about
Functional Programming in the Real World that shows the ideas using examples in C# 3.0 and F#.
I've been Microsoft MVP (for C#) since 2004 and I'm one of the most active members of the F# community. I'm a computer science student at
Charles University of Prague. My hobbies include photography, fractals and of course many things related to computers (except fixing them). My favorite book writers are Terry Pratchett and Philip K Dick and I like paintings by M. C. Escher.
PS: My favorite codeproject icon is .