本文整理汇总了C#中System.Linq.Expressions.MemberInitExpression类的典型用法代码示例。如果您正苦于以下问题:C# MemberInitExpression类的具体用法?C# MemberInitExpression怎么用?C# MemberInitExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberInitExpression类属于System.Linq.Expressions命名空间,在下文中一共展示了MemberInitExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:beyond-code-github,项目名称:xMap,代码行数:29,代码来源:AssignmentVisitor.cs
示例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;
}
开发者ID:sipsorcery,项目名称:sipsorcery,代码行数:7,代码来源:ExpressionVisitor.cs
示例3: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression node)
{
if (node.NewExpression.NodeType == ExpressionType.New)
return node;
return base.VisitMemberInit(node);
}
开发者ID:ArthurYiL,项目名称:EntityFramework.Extended,代码行数:7,代码来源:Evaluator.cs
示例4: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression node)
{
_classes.Push(node.Type);
Expression visitMemberInit = base.VisitMemberInit(node);
_classes.Pop();
return visitMemberInit;
}
开发者ID:kolupaev,项目名称:mongo-csharp-driver,代码行数:7,代码来源:UpdateExpressionVisitor.cs
示例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);
}
开发者ID:RyanDansie,项目名称:SubSonic-3.0,代码行数:34,代码来源:RelationshipIncluder.cs
示例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));
}
开发者ID:respu,项目名称:SimplyFast,代码行数:9,代码来源:PartialEvaluator.cs
示例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);
}
}
开发者ID:nickchal,项目名称:pash,代码行数:11,代码来源:ProjectionAnalyzer.cs
示例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);
}
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:12,代码来源:Evaluator.cs
示例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;
}
开发者ID:dusdong,项目名称:BaseComponent,代码行数:12,代码来源:SelectExpressionVisitor.cs
示例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;
}
开发者ID:dusdong,项目名称:BaseComponent,代码行数:16,代码来源:PropertyFieldExpressionVisitor.cs
示例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;
}
开发者ID:dcga,项目名称:HybridDb,代码行数:17,代码来源:SelectParser.cs
示例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());
}
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:28,代码来源:CypherWithExpressionBuilder.cs
示例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;
}
开发者ID:viceroypenguin,项目名称:Complete.Data,代码行数:19,代码来源:ColumnExtractor.cs
示例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;
}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:21,代码来源:ExpressionInterpreter.cs
示例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);
}
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:23,代码来源:ProjectionMapper.cs
示例16: VisitMemberInit
protected override Expression VisitMemberInit(MemberInitExpression expression)
{
var newExpression = (NewExpression) Visit(expression.NewExpression);
if (newExpression.Type == expression.NewExpression.Type)
{
return base.VisitMemberInit(expression);
}
var bindings = expression.Bindings.Select(b =>
{
var memberAssignment = b as MemberAssignment;
if (memberAssignment == null)
{
return b;
}
var member = newExpression.Type.GetMember(memberAssignment.Member.Name).Single();
if (member.DeclaringType == memberAssignment.Member.DeclaringType)
{
return b;
}
return (MemberBinding) Expression.Bind(member, memberAssignment.Expression);
});
return Expression.MemberInit(newExpression, bindings);
}
开发者ID:TargetProcess,项目名称:Target-Process-Plugins,代码行数:24,代码来源:CtorTypeChanger.cs
示例17: VisitMemberInit
/// <summary>
/// Visits a MemberInitExpression.
/// </summary>
/// <param name="node">The MemberInitExpression.</param>
/// <returns>The MemberInitExpression.</returns>
protected override Expression VisitMemberInit(MemberInitExpression node)
{
throw new NotImplementedException();
}
开发者ID:mpobrien,项目名称:mongo-csharp-driver,代码行数:9,代码来源:ExpressionPrettyPrinter.cs
示例18: VisitMemberInit
/// <summary>
/// Visit a member initialization expression.
/// </summary>
/// <param name="memberInitExp"></param>
/// <returns></returns>
protected virtual Expression VisitMemberInit(MemberInitExpression memberInitExp)
{
NewExpression n = VisitNew(memberInitExp.NewExpression);
IEnumerable<MemberBinding> bindings = VisitBindingList(memberInitExp.Bindings);
return n != memberInitExp.NewExpression || bindings != memberInitExp.Bindings
? Expression.MemberInit(n, bindings)
: memberInitExp;
}
开发者ID:jd-pantheon,项目名称:Titan-Framework-v2,代码行数:14,代码来源:ExpressionVisitor.cs
示例19: VisitMemberInit
private static string VisitMemberInit(MemberInitExpression node)
{
throw new NotImplementedException();
}
开发者ID:bryangrossman,项目名称:ZuoraMagic,代码行数:4,代码来源:ZOQLVisitor.cs
示例20: 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, CypherCapabilities, IEnumerable<JsonConverter>)"/> caters to anonymous types.
/// </remarks>
static string BuildText(
MemberInitExpression expression,
CypherCapabilities capabilities,
IEnumerable<JsonConverter> jsonConvertersThatTheDeserializerWillUse)
{
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, capabilities, jsonConvertersThatTheDeserializerWillUse);
});
return string.Join(", ", bindingTexts.ToArray());
}
开发者ID:pavansystems,项目名称:Neo4jClient,代码行数:31,代码来源:CypherReturnExpressionBuilder.cs
注:本文中的System.Linq.Expressions.MemberInitExpression类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论