本文整理汇总了C#中System.Linq.Expressions.Expression.As方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.As方法的具体用法?C# Expression.As怎么用?C# Expression.As使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.As方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseWhereFragment
public IWhereFragment ParseWhereFragment(DocumentMapping mapping, Expression expression)
{
if (expression is BinaryExpression)
{
return GetWhereFragment(mapping, expression.As<BinaryExpression>());
}
if (expression.NodeType == ExpressionType.Call)
{
return GetMethodCall(mapping, expression.As<MethodCallExpression>());
}
if (expression is MemberExpression && expression.Type == typeof (bool))
{
var locator = JsonLocator(mapping, expression.As<MemberExpression>());
return new WhereFragment("{0} = True".ToFormat(locator), true);
}
if (expression.NodeType == ExpressionType.Not)
{
return GetNotWhereFragment(mapping, expression.As<UnaryExpression>().Operand);
}
if (expression is SubQueryExpression)
{
return GetWhereFragment(mapping, expression.As<SubQueryExpression>());
}
throw new NotSupportedException();
}
示例2: ParseWhereFragment
public static IWhereFragment ParseWhereFragment(Expression expression)
{
if (expression is BinaryExpression)
{
return GetWhereFragment(expression.As<BinaryExpression>());
}
if (expression.NodeType == ExpressionType.Call)
{
return GetMethodCall(expression.As<MethodCallExpression>());
}
throw new NotSupportedException();
}
示例3: JsonLocator
public static string JsonLocator(Type rootType, Expression expression)
{
if (expression is MemberExpression)
{
var memberExpression = expression.As<MemberExpression>();
return JsonLocator(rootType, memberExpression);
}
if (expression is UnaryExpression)
{
return JsonLocator(rootType, expression.As<UnaryExpression>());
}
throw new NotSupportedException();
}
示例4: IsDynamicComponentDictionaryGetter
public static bool IsDynamicComponentDictionaryGetter(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, ISessionFactory sessionFactory, out string memberName)
{
memberName = null;
// A dynamic component must be an IDictionary with a string key.
if (method.Name != "get_Item" || !typeof(IDictionary).IsAssignableFrom(targetObject.Type))
return false;
var key = arguments.First().As<ConstantExpression>();
if (key == null || key.Type != typeof(string))
return false;
// The potential member name
memberName = (string)key.Value;
// Need the owning member (the dictionary).
var member = targetObject.As<MemberExpression>();
if (member == null)
return false;
var metaData = sessionFactory.GetClassMetadata(member.Expression.Type);
if (metaData == null)
return false;
// IDictionary can be mapped as collection or component - is it mapped as a component?
var propertyType = metaData.GetPropertyType(member.Member.Name);
return (propertyType != null && propertyType.IsComponentType);
}
示例5: Value
public static object Value(Expression expression)
{
if (expression is ConstantExpression)
{
// TODO -- handle nulls
// TODO -- check out more types here.
return expression.As<ConstantExpression>().Value;
}
throw new NotSupportedException();
}
示例6: JsonLocator
public static string JsonLocator(Expression expression)
{
if (expression is MemberExpression)
{
var member = expression.As<MemberExpression>().Member;
var locator = "data ->> '{0}'".ToFormat(member.Name);
var memberType = member.GetMemberType();
return memberType == typeof (string) ? locator : locator.ApplyCastToLocator(memberType);
}
throw new NotSupportedException();
}
示例7: ParseWhereFragment
public IWhereFragment ParseWhereFragment(IQueryableDocument mapping, Expression expression)
{
if (expression is LambdaExpression)
{
expression = expression.As<LambdaExpression>().Body;
}
var visitor = new WhereClauseVisitor(this, mapping);
visitor.Visit(expression);
var whereFragment = visitor.ToWhereFragment();
if (whereFragment == null)
{
throw new NotSupportedException("Marten does not (yet) support this Linq query type");
}
return whereFragment;
}
示例8: GetNotWhereFragment
private static IWhereFragment GetNotWhereFragment(Type rootType, Expression expression)
{
if (expression is MemberExpression && expression.Type == typeof(bool))
{
var locator = JsonLocator(rootType, expression.As<MemberExpression>());
return new WhereFragment("({0})::Boolean = False".ToFormat(locator));
}
throw new NotSupportedException();
}
示例9: ParseWhereFragment
public static IWhereFragment ParseWhereFragment(Type rootType, Expression expression)
{
if (expression is BinaryExpression)
{
return GetWhereFragment(rootType, expression.As<BinaryExpression>());
}
if (expression.NodeType == ExpressionType.Call)
{
return GetMethodCall(rootType, expression.As<MethodCallExpression>());
}
if (expression is MemberExpression && expression.Type == typeof(bool))
{
var locator = JsonLocator(rootType, expression.As<MemberExpression>());
return new WhereFragment("({0})::Boolean = True".ToFormat(locator), true);
}
if (expression.NodeType == ExpressionType.Not)
{
return GetNotWhereFragment(rootType, expression.As<UnaryExpression>().Operand);
}
throw new NotSupportedException();
}
示例10: GetNotWhereFragment
private IWhereFragment GetNotWhereFragment(DocumentMapping mapping, Expression expression)
{
if (expression is MemberExpression && expression.Type == typeof (bool))
{
var locator = JsonLocator(mapping, expression.As<MemberExpression>());
return new WhereFragment("({0})::Boolean = False".ToFormat(locator));
}
if (expression.Type == typeof (bool) && expression.NodeType == ExpressionType.NotEqual &&
expression is BinaryExpression)
{
var binaryExpression = expression.As<BinaryExpression>();
var locator = JsonLocator(mapping, binaryExpression.Left);
if (binaryExpression.Right.NodeType == ExpressionType.Constant &&
binaryExpression.Right.As<ConstantExpression>().Value == null)
{
return new WhereFragment($"({locator})::Boolean IS NULL");
}
}
throw new NotSupportedException();
}
示例11: TransformToJsonNode
public TransformToJsonNode(MethodCallExpressionParseInfo parseInfo, Expression transform, Expression optionalSelector) : base(parseInfo, transform as LambdaExpression, optionalSelector as LambdaExpression)
{
var name = transform.As<ConstantExpression>().Value.As<string>();
_operator = new TransformToJsonResultOperator(name);
}
示例12: Value
public static object Value(Expression expression)
{
if (expression is PartialEvaluationExceptionExpression)
{
var partialEvaluationExceptionExpression = expression.As<PartialEvaluationExceptionExpression>();
var inner = partialEvaluationExceptionExpression.Exception;
throw new BadLinqExpressionException($"Error in value expression inside of the query for '{partialEvaluationExceptionExpression.EvaluatedExpression}'. See the inner exception:", inner);
}
if (expression is ConstantExpression)
{
// TODO -- handle nulls
// TODO -- check out more types here.
return expression.As<ConstantExpression>().Value;
}
throw new NotSupportedException();
}