本文整理汇总了C#中System.Linq.Expressions.MemberInitExpression类的典型用法代码示例。如果您正苦于以下问题:C# MemberInitExpression类的具体用法?C# MemberInitExpression怎么用?C# MemberInitExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberInitExpression类属于System.Linq.Expressions命名空间,在下文中一共展示了MemberInitExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression node)
{
var bindings = node.Bindings.ToList();
foreach (var binding in this.fromBindings)
{
if (bindings.All(o => o.Member.Name != binding.Member.Name) && binding.Member is PropertyInfo)
{
var propertyInfo = binding.Member as PropertyInfo;
switch (propertyInfo.PropertyType.ToString())
{
case "System.String":
bindings.Add(Expression.Bind(binding.Member, Expression.Constant("")));
break;
case "System.Int32":
case "System.Int64":
case "System.Int16":
bindings.Add(Expression.Bind(binding.Member, Expression.Constant(0)));
break;
case "System.DateTime":
bindings.Add(Expression.Bind(binding.Member, Expression.Constant(DateTime.MinValue)));
break;
}
}
}
return Expression.MemberInit(node.NewExpression, bindings);
}
示例2: UpdateMemberInit
protected MemberInitExpression UpdateMemberInit(MemberInitExpression init, NewExpression nex, IEnumerable<MemberBinding> bindings)
{
if (nex != init.NewExpression || bindings != init.Bindings) {
return Expression.MemberInit(nex, bindings);
}
return init;
}
示例3: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression node)
{
if (node.NewExpression.NodeType == ExpressionType.New)
return node;
return base.VisitMemberInit(node);
}
示例4: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression node)
{
_classes.Push(node.Type);
Expression visitMemberInit = base.VisitMemberInit(node);
_classes.Pop();
return visitMemberInit;
}
示例5: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression init)
{
if (this.mapping.IsEntity(init.Type))
{
var save = this.includeScope;
this.includeScope = new ScopedDictionary<MemberInfo,bool>(this.includeScope);
Dictionary<MemberInfo, MemberBinding> existing = init.Bindings.ToDictionary(b => b.Member);
List<MemberBinding> newBindings = null;
foreach (var mi in this.mapping.GetMappedMembers(init.Type))
{
if (!existing.ContainsKey(mi) && this.mapping.IsRelationship(mi) && this.policy.IsIncluded(mi))
{
if (this.includeScope.ContainsKey(mi))
{
throw new NotSupportedException(string.Format("Cannot include '{0}.{1}' recursively.", mi.DeclaringType.Name, mi.Name));
}
Expression me = this.mapping.GetMemberExpression(init, mi);
if (newBindings == null)
{
newBindings = new List<MemberBinding>(init.Bindings);
}
newBindings.Add(Expression.Bind(mi, me));
}
}
if (newBindings != null)
{
init = Expression.MemberInit(init.NewExpression, newBindings);
}
this.includeScope = save;
}
return base.VisitMemberInit(init);
}
示例6: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression node)
{
// If we here, than eval the whole block failed, don't touch constructor!
_allowEval = false;
var newExpr = VisitAndConvert(node.NewExpression, "VisitMemberInit");
_allowEval = true;
// ReSharper disable once AssignNullToNotNullAttribute
return node.Update(newExpr, Visit(node.Bindings, VisitMemberBinding));
}
示例7: Analyze
private static void Analyze(MemberInitExpression mie, PathBox pb, DataServiceContext context)
{
if (ClientTypeUtil.TypeOrElementTypeIsEntity(mie.Type))
{
EntityProjectionAnalyzer.Analyze(mie, pb, context);
}
else
{
NonEntityProjectionAnalyzer.Analyze(mie, pb, context);
}
}
示例8: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression node)
{
Expression newExpr = this.Visit(node.NewExpression);
if (newExpr.NodeType == ExpressionType.Constant)
{
// We translated the NewExpression to a ConstantExpression, so by-pass
// VisitMemberInit's validation and return the expression as-is.
return newExpr;
}
return base.VisitMemberInit(node);
}
示例9: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression node)
{
foreach (MemberAssignment binding in node.Bindings)
{
var visitor = new MemberExpressionVisitor(Context);
visitor.Visit(binding.Expression);
visitor.SelectedColumn.Alias = binding.Member.Name;
Columns.Add(visitor.SelectedColumn);
Context.Columns.Add(binding.Member.Name, visitor.SelectedColumn);
}
return node;
}
示例10: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression node)
{
var results = new Dictionary<string, object>();
foreach (MemberAssignment binding in node.Bindings)
{
var visitor = new MemberExpressionVisitor(Context);
visitor.Visit(binding.Expression);
if (visitor.Token.Type != TokenType.Object)
{
throw new NotSupportedException("不支持");
}
results.Add(binding.Member.Name, visitor.Token.Object);
}
Token = Token.Create(results);
return node;
}
示例11: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression expression)
{
var projections = new List<SqlProjectionExpression>();
foreach (var memberBinding in expression.Bindings)
{
var property = memberBinding as MemberAssignment;
if (property == null)
continue;
Visit(property.Expression);
projections.Add(new SqlProjectionExpression((SqlColumnExpression)ast.Pop(), property.Member.Name));
}
ast.Push(new SqlSelectExpression(projections));
return expression;
}
示例12: BuildText
/// <remarks>
/// This build method caters to object initializers, like:
///
/// new MyType { Foo = "Bar", Baz = "Qak" }
///
/// It does not however cater to anonymous types, as they don't compile
/// down to traditional object initializers.
///
/// <see cref="BuildText(NewExpression)"/> caters to anonymous types.
/// </remarks>
string BuildText(MemberInitExpression expression)
{
if (expression.NewExpression.Constructor.GetParameters().Any())
throw new ArgumentException(
"The result type must be constructed using a parameterless constructor. For example: n => new MyResultType { Foo = n.Bar }",
"expression");
var bindingTexts = expression.Bindings.Select(binding =>
{
if (binding.BindingType != MemberBindingType.Assignment)
throw new ArgumentException("All bindings must be assignments. For example: n => new MyResultType { Foo = n.Bar }", "expression");
var memberAssignment = (MemberAssignment)binding;
return BuildStatement(memberAssignment.Expression, binding.Member);
});
return string.Join(", ", bindingTexts.ToArray());
}
示例13: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression init)
{
DoVisitNew(init.NewExpression);
foreach (var x in init.Bindings)
{
var oldMembership = membershipPath;
membershipPath = Expression.MakeMemberAccess(oldMembership, x.Member);
this.VisitBinding(x);
membershipPath = oldMembership;
}
assignments.Add(new AssignmentInformation()
{
Declaration = init,
MembershipPath = membershipPath,
});
return init;
}
示例14: Visit
protected object Visit(MemberInitExpression expression)
{
var obj = this.Visit(expression.NewExpression);
if (obj == InterpretFailed)
{
return obj;
}
foreach (var binding in expression.Bindings)
{
var value = this.Visit(obj, binding);
if (value == InterpretFailed)
{
return value;
}
}
return obj;
}
示例15: VisitMemberInit
private void VisitMemberInit(MemberInitExpression node)
{
foreach (var memberBinding in node.Bindings)
{
var memberAssignment = memberBinding as MemberAssignment;
if (memberAssignment != null)
{
_mappings.Add(new ProjectionMemberMapping
{
Expression = memberAssignment.Expression,
Member = memberAssignment.Member
});
}
else
{
var message = string.Format("Only member assignments are supported in a new expression in $project and $group, but found {0}.",
node.ToString());
throw new NotSupportedException(message);
}
}
VisitNew(node.NewExpression);
}