本文整理汇总了C#中System.Linq.Expressions.MemberBinding类的典型用法代码示例。如果您正苦于以下问题:C# MemberBinding类的具体用法?C# MemberBinding怎么用?C# MemberBinding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberBinding类属于System.Linq.Expressions命名空间,在下文中一共展示了MemberBinding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例7: VisitBinding
protected override MemberBinding VisitBinding(MemberBinding binding)
{
var save = receivingMember;
receivingMember = binding.Member;
var result = base.VisitBinding(binding);
receivingMember = save;
return result;
}
示例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;
}
示例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;
}
示例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());
}
示例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));
}
}
示例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;
}
}
示例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);
}
}
示例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}'");
}
}
示例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));
}
}