本文整理汇总了C#中System.Linq.Expressions.Expression类的典型用法代码示例。如果您正苦于以下问题:C# Expression类的具体用法?C# Expression怎么用?C# Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于System.Linq.Expressions命名空间,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileBulkImporter
public override Expression CompileBulkImporter(EnumStorage enumStorage, Expression writer, ParameterExpression document, ParameterExpression alias, ParameterExpression serializer)
{
var method = writeMethod.MakeGenericMethod(typeof(string));
var dbType = Expression.Constant(DbType);
return Expression.Call(writer, method, alias, dbType);
}
示例2: Visit
protected override Expression Visit(Expression exp)
{
if(exp != null)
return base.Visit(exp);
return exp;
}
示例3: CanBeEvaluatedLocally
// private static methods
private static Boolean CanBeEvaluatedLocally(Expression expression, IQueryProvider queryProvider)
{
// any operation on a query can't be done locally
var constantExpression = expression as ConstantExpression;
if (constantExpression != null)
{
var query = constantExpression.Value as IQueryable;
if (query != null && (queryProvider == null || query.Provider == queryProvider))
{
return false;
}
}
var methodCallExpression = expression as MethodCallExpression;
if (methodCallExpression != null)
{
Type declaringType = methodCallExpression.Method.DeclaringType;
if (declaringType == typeof (Enumerable) || declaringType == typeof (Queryable))
{
return false;
}
}
if (expression.NodeType == ExpressionType.Convert && expression.Type == typeof (Object))
{
return true;
}
if (expression.NodeType == ExpressionType.Parameter || expression.NodeType == ExpressionType.Lambda)
{
return false;
}
return true;
}
示例4: Binding
internal Binding(Expression linqExpression, DbExpression cqtExpression)
{
//Contract.Requires(linqExpression != null);
//Contract.Requires(cqtExpression != null);
LinqExpression = linqExpression;
CqtExpression = cqtExpression;
}
示例5: ExpressionToString
public static string ExpressionToString(Expression expr)
{
if (propertyDebugView == null)
propertyDebugView = typeof(Expression).GetTypeInfo().FindDeclaredProperty("DebugView", ReflectionFlag.NoException | ReflectionFlag.NonPublic | ReflectionFlag.Instance);
return (string)propertyDebugView.GetValue(expr, null);
}
示例6: GetDocumentType
// private static methods
private static Type GetDocumentType(Expression expression)
{
// look for the innermost nested constant of type MongoQueryable<T> and return typeof(T)
var constantExpression = expression as ConstantExpression;
if (constantExpression != null)
{
var constantType = constantExpression.Type;
if (constantType.IsGenericType)
{
var genericTypeDefinition = constantType.GetGenericTypeDefinition();
if (genericTypeDefinition == typeof(MongoQueryable<>))
{
return constantType.GetGenericArguments()[0];
}
}
}
var methodCallExpression = expression as MethodCallExpression;
if (methodCallExpression != null && methodCallExpression.Arguments.Count != 0)
{
return GetDocumentType(methodCallExpression.Arguments[0]);
}
var message = string.Format("Unable to find document type of expression: {0}.", ExpressionFormatter.ToString(expression));
throw new ArgumentOutOfRangeException(message);
}
示例7: Gather
private void Gather(Expression expression)
{
BinaryExpression b = expression as BinaryExpression;
if (b != null)
{
switch (b.NodeType)
{
case ExpressionType.Equal:
case ExpressionType.NotEqual:
if (IsExternalColumn(b.Left) && GetColumn(b.Right) != null)
{
this.columns.Add(GetColumn(b.Right));
}
else if (IsExternalColumn(b.Right) && GetColumn(b.Left) != null)
{
this.columns.Add(GetColumn(b.Left));
}
break;
case ExpressionType.And:
case ExpressionType.AndAlso:
if (b.Type == typeof(bool) || b.Type == typeof(bool?))
{
this.Gather(b.Left);
this.Gather(b.Right);
}
break;
}
}
}
示例8: Get
public IEnumerable<ErrorLog> Get(
Expression<Func<ErrorLog, bool>> filter = null,
Func<IQueryable<ErrorLog>, IOrderedQueryable<ErrorLog>> orderBy = null,
string includeProperties = "")
{
return _unitOfWork.ErrorLogRepository.Get(filter, orderBy, includeProperties);
}
示例9: CreateSetFieldExpression
internal static Expression CreateSetFieldExpression(Expression clone, Expression value, FieldInfo fieldInfo) {
// workaround for readonly fields: use reflection, this is a lot slower but the only way except using il directly
if (fieldInfo.IsInitOnly)
return Expression.Call(Expression.Constant(fieldInfo), _fieldInfoSetValueMethod, clone, Expression.Convert(value, TypeHelper.ObjectType));
return Expression.Assign(Expression.Field(clone, fieldInfo), value);
}
示例10: VisitExpression
public override Expression VisitExpression(Expression expression)
{
if (expression == null)
{
return null;
}
switch ((NhExpressionType)expression.NodeType)
{
case NhExpressionType.Average:
case NhExpressionType.Min:
case NhExpressionType.Max:
case NhExpressionType.Sum:
case NhExpressionType.Count:
case NhExpressionType.Distinct:
return VisitNhAggregate((NhAggregatedExpression)expression);
case NhExpressionType.New:
return VisitNhNew((NhNewExpression)expression);
case NhExpressionType.Star:
return VisitNhStar((NhStarExpression)expression);
}
// Keep this variable for easy examination during debug.
var expr = base.VisitExpression(expression);
return expr;
}
示例11: UnaryExpression
internal UnaryExpression(ExpressionType nodeType, Expression expression, Type type, MethodInfo method)
{
_operand = expression;
_method = method;
_nodeType = nodeType;
_type = type;
}
示例12: PrettyPrint
// public methods
/// <summary>
/// Pretty prints an Expression.
/// </summary>
/// <param name="node">The Expression to pretty print.</param>
/// <returns>A string containing the pretty printed Expression.</returns>
public string PrettyPrint(Expression node)
{
_sb = new StringBuilder();
_indentation = "";
Visit(node);
return _sb.ToString();
}
示例13: CreatePropertyAccessExpression
private Expression CreatePropertyAccessExpression(Expression instance, string propertyName)
{
CallSiteBinder binder = Binder.GetMember(CSharpBinderFlags.None, propertyName,
typeof(DynamicPropertyAccessExpressionBuilder), new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });
return Expression.Dynamic(binder, typeof(object), new[] { instance });
}
示例14: EvaluateUnsupported
EvaluationResult EvaluateUnsupported(Expression expression) {
try {
return EvaluationResult.Success(expression.Type, Expression.Lambda<Func<object>>(expression.Box()).Compile()());
} catch(Exception e) {
return EvaluationResult.Failure(expression, e);
}
}
示例15: BuildExpression
public override Expression BuildExpression(Expression expression, int level)
{
var expr = Sequence.BuildExpression(expression, level);
if (expression == null)
{
var q =
from col in SqlQuery.Select.Columns
where !col.CanBeNull()
select SqlQuery.Select.Columns.IndexOf(col);
var idx = q.DefaultIfEmpty(-1).First();
if (idx == -1)
idx = SqlQuery.Select.Add(new SqlValue((int?) 1));
var n = ConvertToParentIndex(idx, this);
var e = Expression.Call(
ExpressionBuilder.DataReaderParam,
ReflectionHelper.DataReader.IsDBNull,
Expression.Constant(n)) as Expression;
var defaultValue = _defaultValue ?? Expression.Constant(null, expr.Type);
expr = Expression.Condition(e, defaultValue, expr);
}
return expr;
}