本文整理汇总了C#中System.Linq.Expressions.UnaryExpression类的典型用法代码示例。如果您正苦于以下问题:C# UnaryExpression类的具体用法?C# UnaryExpression怎么用?C# UnaryExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnaryExpression类属于System.Linq.Expressions命名空间,在下文中一共展示了UnaryExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArrayLength
internal static ArrayLength ArrayLength(UnaryExpression expression)
{
return new ArrayLength()
{
Operand = Serialize(expression.Operand),
}.Apply(n => n.Type = TypeRef.Serialize(expression.Type));
}
示例2: VisitUnary
protected override Expression VisitUnary(UnaryExpression node)
{
if (node.NodeType == ExpressionType.Not && node.Operand is MemberExpression)
{
return base.VisitUnary(node);
}
var exp = base.VisitUnary(node);
if (node.NodeType == ExpressionType.Not)
{
string condition = _conditionStack.Pop();
_conditionStack.Push("(NOT " + condition + ")");
}
else if (node.NodeType == ExpressionType.Convert)
{
if (node.Operand is ConstantExpression)
{
_constStack.Push((node.Operand as ConstantExpression).Value);
}
}
else
{
throw new Exception("未支持一元操作符:" + node.NodeType.ToString());
}
return exp;
}
示例3: VisitConvert
private static SqlExpression VisitConvert(UnaryExpression expression)
{
if (expression.Operand.NodeType == ExpressionType.MemberAccess) {
return VisitMemberAccess((MemberExpression)expression.Operand);
}
throw new NotImplementedException();
}
示例4: VisitUnary
protected override Expression VisitUnary(UnaryExpression node)
{
switch (node.NodeType)
{
case ExpressionType.Not:
if (node.Operand is SubQueryExpression)
{
var nested = new WhereClauseVisitor(_parent, _mapping);
nested.Visit(node.Operand);
var @where = new NotWhereFragment(nested.ToWhereFragment());
_register.Peek()(@where);
}
else
{
var visitor = new NotVisitor(this, _mapping, _register.Peek());
visitor.Visit(node);
}
return null;
}
return base.VisitUnary(node);
}
示例5: Quote
internal static Quote Quote(UnaryExpression expression)
{
return new Quote()
{
Operand = Serialize(expression.Operand),
}.Apply(n => n.Type = TypeRef.Serialize(expression.Type));
}
示例6: VisitUnary
protected override Expression VisitUnary(UnaryExpression node) {
if (node.NodeType == ExpressionType.Convert) {
return Expression.ConvertChecked(node.Operand, node.Type);
}
return base.VisitUnary(node);
}
示例7: ParseUnaryNot
static Node ParseUnaryNot(UnaryExpression e)
{
string suffix = e.Operand is BinaryExpression ? ")" : null;
string prefix = e.Operand is BinaryExpression ? "!(" : "!";
return new UnaryNode { Prefix = prefix, Operand = Parse(e.Operand), PrefixValue = GetValue(e), Suffix = suffix };
}
示例8: VisitUnary
protected override Expression VisitUnary(UnaryExpression u)
{
throw new NotSupportedException(
string.Format(
"The unary operator '{0}' is not supported",
u.NodeType));
}
示例9: VisitUnary
protected override Expression VisitUnary(UnaryExpression node)
{
return Expression.MakeUnary(
node.NodeType,
Visit(node.Operand),
node.Type);
}
示例10: VisitUnary
protected override Expression VisitUnary(UnaryExpression unaryExpression)
{
if (unaryExpression.NodeType == ExpressionType.Not && unaryExpression.Type.GetUnwrappedNullableType() == typeof(bool))
{
var operand = this.Visit(unaryExpression.Operand);
if (operand is BitBooleanExpression)
{
return Expression.MakeUnary(unaryExpression.NodeType, Expression.Equal(operand, Expression.Constant(true, operand.Type)), typeof(bool));
}
}
else if (unaryExpression.NodeType == ExpressionType.Convert
&& unaryExpression.Type.GetUnwrappedNullableType() == typeof(bool)
&& unaryExpression.Operand.Type.GetUnwrappedNullableType() != typeof(bool))
{
var operand = this.Visit(unaryExpression.Operand);
if (operand is BitBooleanExpression)
{
return Expression.MakeUnary(unaryExpression.NodeType, Expression.Equal(operand, Expression.Constant(true, operand.Type)), typeof(bool));
}
}
return base.VisitUnary(unaryExpression);
}
示例11: VisitUnary
protected override Expression VisitUnary(UnaryExpression node)
{
if (node.NodeType != ExpressionType.Convert && node.NodeType != ExpressionType.ConvertChecked)
{
return base.VisitUnary(node);
}
if (node.Operand.NodeType != ExpressionType.MemberAccess)
{
return base.VisitUnary(node);
}
if (!ReflectionHelper.IsNullable(node.Type))
{
return base.VisitUnary(node);
}
MemberExpression memberNode = node.Operand as MemberExpression;
if (memberNode.Expression == null)
{
// Static member access cannot be rewritten
return base.VisitUnary(node);
}
return this.CreateSafeMemberAccessExpression(node.Operand as MemberExpression, node.Type);
}
示例12: AddQueryPart
public void AddQueryPart(UnaryExpression leftItem, ConstantExpression rightValue, ExpressionType nodeType)
{
if(leftItem.Operand is MethodCallExpression)
{
var unaryOperation = (MethodCallExpression)leftItem.Operand;
if(unaryOperation.Method.Name != "get_Item")
{
throw new InvalidOperationException("Queries based on " + leftItem.Method.Name + " are not yet supported.");
}
if(unaryOperation.Arguments[0] is ConstantExpression)
{
var attributeRef = ((ConstantExpression) unaryOperation.Arguments[0]).Value;
AddCriteriaToActiveSearchCondition(attributeRef.ToString(), rightValue.Value, GetSearchRelationType(nodeType));
}
else
{
throw new InvalidOperationException("Only constant expressions are currently supported.");
}
}
else
{
throw new InvalidOperationException("Queries based on " + leftItem.Method.Name + " are not yet supported.");
}
}
示例13: VisitUnary
protected override Expression VisitUnary(UnaryExpression u)
{
if (u.NodeType == ExpressionType.Quote)
{
return base.Visit(u.Operand);
}
return base.VisitUnary(u);
}
示例14: Unbox
internal static Unbox Unbox(UnaryExpression expression)
{
return new Unbox()
{
Operand = Serialize(expression.Operand),
Type = TypeRef.Serialize(expression.Type),
};
}
示例15: VisitUnary
protected override Expression VisitUnary(UnaryExpression u)
{
u = (UnaryExpression)base.VisitUnary(u);
if (u.NodeType != ExpressionType.Not)
return u;
return Invert(u.Operand, u);
}