本文整理汇总了C#中System.Linq.Expressions.NewArrayExpression类的典型用法代码示例。如果您正苦于以下问题:C# NewArrayExpression类的具体用法?C# NewArrayExpression怎么用?C# NewArrayExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NewArrayExpression类属于System.Linq.Expressions命名空间,在下文中一共展示了NewArrayExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewArrayInit
internal static NewArrayInit NewArrayInit(NewArrayExpression expression)
{
return new NewArrayInit()
{
Type = TypeRef.Serialize(expression.Type.GetElementType()),
Expressions = expression.Expressions.Any()
? expression.Expressions.Select(Serialize).ToArray()
: null,
}.Apply(n => n.Type = TypeRef.Serialize(expression.Type));
}
示例2: CreateParamArrayConstraint
private IArgumentConstraint CreateParamArrayConstraint(NewArrayExpression expression)
{
var result = new List<IArgumentConstraint>();
foreach (var argumentExpression in expression.Expressions)
{
result.Add(this.GetArgumentConstraintFromExpression(argumentExpression));
}
return new AggregateArgumentConstraint(result);
}
示例3: VisitNewArray
protected override Expression VisitNewArray(NewArrayExpression node)
{
List<Visitor> elementVisitors = node.Expressions.Select(_ => new Visitor()).ToList();
List<Expression> elementExpressions = elementVisitors.Zip(node.Expressions, (v, e) => v.Visit(e)).ToList();
NewArrayExpression arrayExpression = Expression.NewArrayInit(elementExpressions.First().Type, elementExpressions);
foreach (Visitor visitor in elementVisitors)
_captureNode.AddChild(visitor.CaptureNode);
return arrayExpression;
}
示例4: ProcessNewArrayExpression
protected virtual Expression ProcessNewArrayExpression(NewArrayExpression expression)
{
var notFirst = false;
foreach (var member in expression.Expressions)
{
if (notFirst)
CommandTextBuilder.Append(",");
ProcessExpression(member);
notFirst = true;
}
return expression;
}
示例5: ParseExpression
static Node ParseExpression(NewArrayExpression e)
{
switch (e.NodeType)
{
case ExpressionType.NewArrayInit:
Type t = e.Type.GetElementType();
return new NewArrayNode
{
Items = e.Expressions.Select(Parse).ToList(),
Type = NameOfType(t)
};
case ExpressionType.NewArrayBounds:
//todo:
default:
throw new ArgumentOutOfRangeException();
}
}
示例6: VisitNewArray
protected override Expression VisitNewArray(NewArrayExpression node)
{
if (node.Type != typeof(Byte[]))
{
String message = String.Format("Resources.ExpressionEvaluatorTypeNotSupported {0}", node.Type);
throw new NotSupportedException(message);
}
var array = new Byte[node.Expressions.Count];
for (int i = 0; i < node.Expressions.Count; i++)
{
ConstantExpression result = TryToEvaluate(node.Expressions[i]);
array[i] = (Byte)result.Value;
}
return Expression.Constant(array, node.Type);
}
示例7: VisitNewArray
protected override Expression VisitNewArray(NewArrayExpression expression)
{
if (expression.Type.GetArrayRank() == 1 && !expression.Type.GetElementType().IsDataAccessObjectType())
{
if (expression.Expressions.All(c => c.Type.IsDataAccessObjectType()))
{
if (expression.NodeType == ExpressionType.NewArrayInit)
{
return Expression.NewArrayInit(typeof(DataAccessObject), this.VisitExpressionList(expression.Expressions));
}
else
{
return Expression.NewArrayBounds(typeof(DataAccessObject), this.VisitExpressionList(expression.Expressions));
}
}
}
return base.VisitNewArray(expression);
}
示例8: VisitNewArray
protected override Expression VisitNewArray(NewArrayExpression na)
{
this.Write("new ");
this.Write(this.GetTypeName(TypeHelper.GetElementType(na.Type)));
this.Write("[] {");
if (na.Expressions.Count > 1)
this.WriteLine(Indentation.Inner);
this.VisitExpressionList(na.Expressions);
if (na.Expressions.Count > 1)
this.WriteLine(Indentation.Outer);
this.Write("}");
return na;
}
示例9: CreateArrayInitExpressions
static IEnumerable<Expression> CreateArrayInitExpressions(NewArrayExpression newArray, Expression valueExpression, Expression indexExpression)
{
if (newArray.NodeType == ExpressionType.NewArrayInit)
{
var indexGetter = (Func<int>) Expression.Lambda(indexExpression).Compile();
var index = indexGetter();
var expressions = newArray.Expressions.ToArray();
if (index >= newArray.Expressions.Count)
{
Array.Resize(ref expressions, index + 1);
}
expressions[index] = valueExpression;
return expressions;
}
return new[] {valueExpression};
}
示例10: UpdateNewArray
protected NewArrayExpression UpdateNewArray(NewArrayExpression na, Type arrayType, IEnumerable<Expression> expressions)
{
if (expressions != na.Expressions || na.Type != arrayType)
{
if (na.NodeType == ExpressionType.NewArrayInit)
{
return Expression.NewArrayInit(arrayType.GetElementType(), expressions);
}
else
{
return Expression.NewArrayBounds(arrayType.GetElementType(), expressions);
}
}
return na;
}
示例11: VisitNewArray
protected virtual Expression VisitNewArray(NewArrayExpression na)
{
IEnumerable<Expression> exprs = this.VisitExpressionList(na.Expressions);
return this.UpdateNewArray(na, na.Type, exprs);
}
示例12: VisitNewArray
internal override Expression VisitNewArray(NewArrayExpression na)
{
throw new NotSupportedException(Strings.ALinq_NewArrayNotSupported);
}
示例13: VisitNewArray
protected virtual System.Linq.Expressions.Expression VisitNewArray(NewArrayExpression na)
{
IEnumerable<System.Linq.Expressions.Expression> exprs = VisitExpressionList(na.Expressions);
// ReSharper disable once PossibleUnintendedReferenceComparison
if(exprs != na.Expressions)
{
if(na.NodeType == ExpressionType.NewArrayInit)
{
return System.Linq.Expressions.Expression.NewArrayInit(na.Type.GetElementType(), exprs);
}
return System.Linq.Expressions.Expression.NewArrayBounds(na.Type.GetElementType(), exprs);
}
return na;
}
示例14: VisitNewArray
/// <summary>
/// Visit a new array expression.
/// </summary>
/// <param name="newArrayExp"></param>
/// <returns></returns>
protected virtual Expression VisitNewArray(NewArrayExpression newArrayExp)
{
IEnumerable<Expression> exprs = VisitList(newArrayExp.Expressions);
if (exprs != newArrayExp.Expressions)
{
return newArrayExp.NodeType == ExpressionType.NewArrayInit
? Expression.NewArrayInit(newArrayExp.Type.GetElementType(), exprs)
: Expression.NewArrayBounds(newArrayExp.Type.GetElementType(), exprs);
}
return newArrayExp;
}
示例15: VisitNewArray
internal override Expression VisitNewArray(NewArrayExpression na)
{
throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjectionToEntity(this.type, na.ToString()));
}