本文整理汇总了C#中System.Linq.Expressions.MemberBinding类的典型用法代码示例。如果您正苦于以下问题:C# MemberBinding类的具体用法?C# MemberBinding怎么用?C# MemberBinding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberBinding类属于System.Linq.Expressions命名空间,在下文中一共展示了MemberBinding类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TransformMixinMethodExpression
/// <summary>
/// Transforms a call to <code>entity.Mixin<T>()</code> to <code>new MixinType { Properties, ... }</code>
/// </summary>
/// <param name="method">The method call expression.</param>
/// <returns>The</returns>
public Expression TransformMixinMethodExpression(MethodCallExpression method)
{
var mixinType = method.Type;
var entityType = method.Object.Type;
string prefix = $"{mixinType.Name}_";
// Get the available properties of the mixin.
var entity = _model.GetEntityType(entityType);
var properties = entity
.GetProperties()
.Where(p => p.Name.StartsWith(prefix))
.ToArray();
// Create an object initializer expression.
var ctor = Expression.New(mixinType);
var memberBindings = new MemberBinding[properties.Length];
for (int i = 0; i < properties.Length; i++)
{
var property = properties[i];
string propertyName = property.Name.Replace(prefix, "");
var member = mixinType.GetProperty(propertyName);
var value = Expression.Call(
EntityQueryModelVisitor.PropertyMethodInfo.MakeGenericMethod(member.PropertyType),
method.Object,
Expression.Constant(property.Name));
memberBindings[i] = Expression.Bind(member, value);
}
return Expression.MemberInit(ctor, memberBindings);
}
开发者ID:Antaris,项目名称:EntityFrameworkMixins,代码行数:36,代码来源:MixinExpressionVisitor.cs
示例2: CreateConstructorExpression
public static CreateInstance CreateConstructorExpression(IContainerContext containerContext, ResolutionConstructor resolutionConstructor,
ResolutionMember[] members = null)
{
var strategyParameter = Expression.Constant(containerContext.ResolutionStrategy, typeof(IResolutionStrategy));
var resolutionInfoParameter = Expression.Parameter(typeof(ResolutionInfo), "resolutionInfo");
var arguments = CreateExpressionFromResolutionTargets(resolutionConstructor.Parameters, strategyParameter, resolutionInfoParameter);
var newExpression = Expression.New(resolutionConstructor.Constructor, arguments);
if (members == null || members.Length == 0)
return Expression.Lambda<CreateInstance>(newExpression, resolutionInfoParameter).Compile();
var length = members.Length;
var propertyExpressions = new MemberBinding[length];
for (var i = 0; i < length; i++)
{
var member = members[i];
var propertyExpression = Expression.Bind(member.MemberInfo,
CreateResolutionTargetExpression(member.ResolutionTarget, strategyParameter,
resolutionInfoParameter));
propertyExpressions[i] = propertyExpression;
}
var initExpression = Expression.MemberInit(newExpression, propertyExpressions);
return Expression.Lambda<CreateInstance>(initExpression, resolutionInfoParameter).Compile();
}
开发者ID:z4kn4fein,项目名称:stashbox,代码行数:28,代码来源:ExpressionDelegateFactory.cs
示例3: CreateEditableMemberBinding
public static EditableMemberBinding CreateEditableMemberBinding(MemberBinding member)
{
if (member is MemberAssignment) return new EditableMemberAssignment(member as MemberAssignment);
else if (member is MemberListBinding) return new EditableMemberListBinding(member as MemberListBinding);
else if (member is MemberMemberBinding) return new EditableMemberMemberBinding(member as MemberMemberBinding);
else return null;
}
开发者ID:juanplopes,项目名称:simple,代码行数:7,代码来源:EditableMemberBinding.cs
示例4: BindToProjectedWrapperMany
private static void BindToProjectedWrapperMany(Expression[] bindingExpressions, int expressionStartIndex, MemberBinding[] bindings, int bindingStartIndex)
{
int propertyIndex = 0;
while ((propertyIndex < (precreatedProjectedWrapperTypes.Length - 1)) && ((propertyIndex + expressionStartIndex) < bindingExpressions.Length))
{
bindings[bindingStartIndex + propertyIndex] = BindToProjectedProperty(typeof(ProjectedWrapperMany), propertyIndex, bindingExpressions[expressionStartIndex + propertyIndex]);
propertyIndex++;
}
if (bindingExpressions.Length <= ((precreatedProjectedWrapperTypes.Length - 1) + expressionStartIndex))
{
while (propertyIndex < (precreatedProjectedWrapperTypes.Length - 1))
{
bindings[bindingStartIndex + propertyIndex] = BindToProjectedProperty(typeof(ProjectedWrapperMany), propertyIndex, Expression.Constant(string.Empty, typeof(string)));
propertyIndex++;
}
bindings[(bindingStartIndex + precreatedProjectedWrapperTypes.Length) - 1] = Expression.Bind(typeof(ProjectedWrapperMany).GetProperty("Next"), Expression.MemberInit(Expression.New(typeof(ProjectedWrapperManyEnd)), new MemberBinding[] { Expression.Bind(typeof(ProjectedWrapperManyEnd).GetProperty("ResourceTypeName"), Expression.Constant(string.Empty, typeof(string))) }));
}
else
{
int length = bindingExpressions.Length - ((precreatedProjectedWrapperTypes.Length - 1) + expressionStartIndex);
if (length > (precreatedProjectedWrapperTypes.Length - 1))
{
length = precreatedProjectedWrapperTypes.Length;
}
MemberBinding[] bindingArray = new MemberBinding[precreatedProjectedWrapperTypes.Length + 2];
bindingArray[0] = Expression.Bind(typeof(ProjectedWrapperMany).GetProperty("ResourceTypeName"), Expression.Constant(string.Empty, typeof(string)));
bindingArray[1] = Expression.Bind(typeof(ProjectedWrapperMany).GetProperty("PropertyNameList"), Expression.Constant(string.Empty, typeof(string)));
BindToProjectedWrapperMany(bindingExpressions, (expressionStartIndex + precreatedProjectedWrapperTypes.Length) - 1, bindingArray, 2);
Expression expression = Expression.MemberInit(Expression.New(typeof(ProjectedWrapperMany)), bindingArray);
bindings[(bindingStartIndex + precreatedProjectedWrapperTypes.Length) - 1] = Expression.Bind(typeof(ProjectedWrapperMany).GetProperty("Next"), expression);
}
}
开发者ID:nickchal,项目名称:pash,代码行数:32,代码来源:ProjectedWrapper.cs
示例5: CreateExpression
public static Expression CreateExpression(IContainerContext containerContext, ResolutionConstructor resolutionConstructor, ResolutionInfo resolutionInfo,
Expression resolutionInfoExpression, ResolutionMember[] members = null)
{
var length = resolutionConstructor.Parameters.Length;
var arguments = new Expression[length];
for (var i = 0; i < length; i++)
{
var parameter = resolutionConstructor.Parameters[i];
arguments[i] = containerContext.ResolutionStrategy.GetExpressionForResolutionTarget(parameter, resolutionInfo, resolutionInfoExpression);
}
var newExpression = Expression.New(resolutionConstructor.Constructor, arguments);
if (members == null || members.Length == 0) return newExpression;
{
var propLength = members.Length;
var propertyExpressions = new MemberBinding[propLength];
for (var i = 0; i < propLength; i++)
{
var member = members[i];
var propertyExpression = Expression.Bind(member.MemberInfo,
containerContext.ResolutionStrategy.GetExpressionForResolutionTarget(member.ResolutionTarget, resolutionInfo, resolutionInfoExpression));
propertyExpressions[i] = propertyExpression;
}
return Expression.MemberInit(newExpression, propertyExpressions);
}
}
开发者ID:z4kn4fein,项目名称:stashbox,代码行数:29,代码来源:ExpressionDelegateFactory.cs
示例6: VisitMemberBinding
protected override MemberBinding VisitMemberBinding(MemberBinding memberBinding)
{
if(memberBinding.BindingType == MemberBindingType.Assignment)
{
#if PORTABLE
var propertyInfo = memberBinding.Member as PropertyInfo;
var assignment = memberBinding as MemberAssignment;
if (propertyInfo != null
&& assignment != null
&& assignment.Expression.Type.IsValueType
&& !propertyInfo.PropertyType.IsValueType)
{
var valueExpression = Expression.TypeAs(VisitExpression(assignment.Expression), propertyInfo.PropertyType);
return Expression.Bind(memberBinding.Member, valueExpression);
}
#else
if (memberBinding.Member.MemberType == MemberTypes.Property)
{
var propertyInfo = memberBinding.Member as PropertyInfo;
var assignment = memberBinding as MemberAssignment;
if (assignment.Expression.Type.IsValueType && !propertyInfo.PropertyType.IsValueType)
{
var valueExpression = Expression.TypeAs(VisitExpression(assignment.Expression), propertyInfo.PropertyType);
return Expression.Bind(memberBinding.Member, valueExpression);
}
}
#endif
}
return base.VisitMemberBinding(memberBinding);
}
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:30,代码来源:SparqlGeneratorSelectExpressionBuilder.cs
示例7: VisitBinding
protected override MemberBinding VisitBinding(MemberBinding binding)
{
var save = receivingMember;
receivingMember = binding.Member;
var result = base.VisitBinding(binding);
receivingMember = save;
return result;
}
开发者ID:ScottWeinstein,项目名称:Linq2KdbQ,代码行数:8,代码来源:QExecutionBuilder.cs
示例8: VisitBinding
protected override MemberBinding VisitBinding(MemberBinding node)
{
var elementName = BsonClassMap.LookupClassMap(_classes.Peek()).GetMemberMap(node.Member.Name).ElementName;
_assigments.Push(elementName);
MemberBinding visitMemberBinding = base.VisitBinding(node);
_assigments.Pop();
return visitMemberBinding;
}
开发者ID:kolupaev,项目名称:mongo-csharp-driver,代码行数:9,代码来源:UpdateExpressionVisitor.cs
示例9: Decode
public MemberBinding[] Decode(ref byte* data, ref int remainingBytes, bool doNotCheckBounds)
{
int count = intCodec.Decode(ref data, ref remainingBytes, doNotCheckBounds);
if (count == -1)
return null;
var result = new MemberBinding[count];
for (int i = 0; i < count; i++)
result[i] = memberBindingCodec.Decode(ref data, ref remainingBytes, doNotCheckBounds);
return result;
}
开发者ID:yonglehou,项目名称:SharpRPC,代码行数:10,代码来源:MemberBindingCollectionCodec.cs
示例10: GetMutator
public static IMemberBindingMutator GetMutator(MemberBinding memberBinding)
{
if (memberBinding is MemberAssignment)
return new MemberAssignmentMutator((MemberAssignment)memberBinding);
if (memberBinding is MemberMemberBinding)
return new MemberMemberBindingMutator((MemberMemberBinding)memberBinding);
if (memberBinding is MemberListBinding)
return new MemberListBindingMutator((MemberListBinding)memberBinding);
throw Error.BadArgument("S0040: Unknown Expression Type '{0}'", memberBinding.GetType());
}
开发者ID:TheRealDuckboy,项目名称:mono-soc-2008,代码行数:10,代码来源:MemberBindingMutatorFactory.cs
示例11: VisitBinding
protected virtual MemberBinding VisitBinding (MemberBinding binding)
{
switch (binding.BindingType)
{
case MemberBindingType.Assignment:
return VisitMemberAssignment ((MemberAssignment)binding);
default:
throw new ArgumentException (string.Format ("Unhandled binding type '{0}'", binding.BindingType));
}
}
开发者ID:kstreet,项目名称:Street.MvxPlugins,代码行数:10,代码来源:ExpressionVisitor.cs
示例12: ReduceMemberBinding
internal static Expression ReduceMemberBinding(ParameterExpression objVar, MemberBinding binding) {
MemberExpression member = Expression.MakeMemberAccess(objVar, binding.Member);
switch (binding.BindingType) {
case MemberBindingType.Assignment:
return Expression.Assign(member, ((MemberAssignment)binding).Expression);
case MemberBindingType.ListBinding:
return ReduceListInit(member, ((MemberListBinding)binding).Initializers, false);
case MemberBindingType.MemberBinding:
return ReduceMemberInit(member, ((MemberMemberBinding)binding).Bindings, false);
default: throw Assert.Unreachable;
}
}
开发者ID:mscottford,项目名称:ironruby,代码行数:12,代码来源:MemberInitExpression.cs
示例13: VisitBinding
internal virtual MemberBinding VisitBinding(MemberBinding binding) {
switch (binding.BindingType) {
case MemberBindingType.Assignment:
return this.VisitMemberAssignment((MemberAssignment)binding);
case MemberBindingType.MemberBinding:
return this.VisitMemberMemberBinding((MemberMemberBinding)binding);
case MemberBindingType.ListBinding:
return this.VisitMemberListBinding((MemberListBinding)binding);
default:
throw Error.UnhandledBindingType(binding.BindingType);
}
}
开发者ID:modulexcite,项目名称:LinqToSQL2,代码行数:12,代码来源:ExpressionVisitor.cs
示例14: VisitBinding
protected virtual MemberBinding VisitBinding(MemberBinding binding)
{
switch (binding.BindingType)
{
case MemberBindingType.Assignment:
return this.VisitMemberAssignment((MemberAssignment)binding);
case MemberBindingType.MemberBinding:
return this.VisitMemberMemberBinding((MemberMemberBinding)binding);
case MemberBindingType.ListBinding:
return this.VisitMemberListBinding((MemberListBinding)binding);
default:
throw new Exception($"Unhandled binding type '{binding.BindingType}'");
}
}
开发者ID:ServiceStack,项目名称:ServiceStack.OrmLite,代码行数:14,代码来源:SqlExpressionVisitor.cs
示例15: VisitBinding
protected virtual MemberBinding VisitBinding(MemberBinding binding, Stack<string> stack, Stack<IElasticPropertyAttribute> properties)
{
switch (binding.BindingType)
{
case MemberBindingType.Assignment:
return this.VisitMemberAssignment((MemberAssignment)binding, stack, properties);
case MemberBindingType.MemberBinding:
return this.VisitMemberMemberBinding((MemberMemberBinding)binding, stack, properties);
case MemberBindingType.ListBinding:
return this.VisitMemberListBinding((MemberListBinding)binding, stack, properties);
default:
throw new Exception(string.Format("Unhandled binding type '{0}'", binding.BindingType));
}
}
开发者ID:BiYiTuan,项目名称:elasticsearch-net,代码行数:14,代码来源:ExpressionVisitor.cs
示例16: Create
internal static MemberBindingNode Create(INodeFactory factory, MemberBinding memberBinding)
{
MemberBindingNode memberBindingNode = null;
if (memberBinding is MemberAssignment)
memberBindingNode = new MemberAssignmentNode(factory, (MemberAssignment)memberBinding);
else if (memberBinding is MemberListBinding)
memberBindingNode = new MemberListBindingNode(factory, (MemberListBinding)memberBinding);
else if (memberBinding is MemberMemberBinding)
memberBindingNode = new MemberMemberBindingNode(factory, (MemberMemberBinding)memberBinding);
else if (memberBinding != null)
throw new ArgumentException("Unknown member binding of type " + memberBinding.GetType(), "memberBinding");
return memberBindingNode;
}
开发者ID:jonparker,项目名称:Serialize.Linq,代码行数:15,代码来源:MemberBindingNode.cs
示例17: ReduceMemberBinding
internal static Expression ReduceMemberBinding(ParameterExpression objVar, MemberBinding binding)
{
MemberExpression left = Expression.MakeMemberAccess(objVar, binding.Member);
switch (binding.BindingType)
{
case MemberBindingType.Assignment:
return Expression.Assign(left, ((MemberAssignment) binding).Expression);
case MemberBindingType.MemberBinding:
return ReduceMemberInit(left, ((MemberMemberBinding) binding).Bindings, false);
case MemberBindingType.ListBinding:
return ReduceListInit(left, ((MemberListBinding) binding).Initializers, false);
}
throw ContractUtils.Unreachable;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:16,代码来源:MemberInitExpression.cs
示例18: AreEqualBinding
protected virtual bool AreEqualBinding(MemberBinding x, MemberBinding y)
{
if (x.BindingType != y.BindingType)
return false;
switch (x.BindingType)
{
case MemberBindingType.Assignment:
return this.AreEqualMemberAssignment((MemberAssignment)x, (MemberAssignment)y);
case MemberBindingType.MemberBinding:
return this.AreEqualMemberMemberBinding((MemberMemberBinding)x, (MemberMemberBinding)y);
case MemberBindingType.ListBinding:
return this.AreEqualMemberListBinding((MemberListBinding)x, (MemberListBinding)y);
default:
throw new Exception(string.Format("Unhandled binding type '{0}'", y.BindingType));
}
}
开发者ID:zapov,项目名称:Serialize.Linq,代码行数:17,代码来源:ExpressionComparer.cs
示例19: Bind
internal static MemberBinding[] Bind(Expression[] bindingExpressions, Type projectedWrapperType)
{
MemberBinding[] bindingArray;
int length = bindingExpressions.Length;
if (length <= (precreatedProjectedWrapperTypes.Length + 1))
{
bindingArray = new MemberBinding[length];
BindResourceTypeAndPropertyNameList(projectedWrapperType, bindingArray, bindingExpressions);
for (int i = 0; i < (length - 2); i++)
{
bindingArray[i + 2] = BindToProjectedProperty(projectedWrapperType, i, bindingExpressions[i + 2]);
}
return bindingArray;
}
bindingArray = new MemberBinding[precreatedProjectedWrapperTypes.Length + 2];
BindResourceTypeAndPropertyNameList(projectedWrapperType, bindingArray, bindingExpressions);
BindToProjectedWrapperMany(bindingExpressions, 2, bindingArray, 2);
return bindingArray;
}
开发者ID:nickchal,项目名称:pash,代码行数:19,代码来源:ProjectedWrapper.cs
示例20: Visit
protected object Visit(object obj, MemberBinding binding)
{
switch (binding.BindingType)
{
case MemberBindingType.Assignment:
var assignment = ((MemberAssignment)binding);
var value = this.Visit(assignment.Expression);
if (value == InterpretFailed)
{
return value;
}
var fieldInfo = assignment.Member as FieldInfo;
if (fieldInfo != null)
{
fieldInfo.SetValue(obj, value);
return binding;
}
var propertyInfo = assignment.Member as PropertyInfo;
if (propertyInfo != null)
{
propertyInfo.SetValue(obj, value, null);
return binding;
}
return InterpretFailed;
}
return InterpretFailed;
}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:37,代码来源:ExpressionInterpreter.cs
注:本文中的System.Linq.Expressions.MemberBinding类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论