本文整理汇总了C#中ExpressionResolutionResult类的典型用法代码示例。如果您正苦于以下问题:C# ExpressionResolutionResult类的具体用法?C# ExpressionResolutionResult怎么用?C# ExpressionResolutionResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExpressionResolutionResult类属于命名空间,在下文中一共展示了ExpressionResolutionResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindNullableExpression
private static MemberAssignment BindNullableExpression(PropertyMap propertyMap,
ExpressionResolutionResult result)
{
if (result.ResolutionExpression.NodeType == ExpressionType.MemberAccess)
{
var memberExpr = (MemberExpression) result.ResolutionExpression;
if (memberExpr.Expression != null && memberExpr.Expression.NodeType == ExpressionType.MemberAccess)
{
var destType = propertyMap.DestinationPropertyType;
var parentExpr = memberExpr.Expression;
Expression expressionToBind = Expression.Convert(memberExpr, destType);
var nullExpression = Expression.Convert(Expression.Constant(null), destType);
while (parentExpr.NodeType != ExpressionType.Parameter)
{
memberExpr = (MemberExpression) memberExpr.Expression;
parentExpr = memberExpr.Expression;
expressionToBind = Expression.Condition(
Expression.Equal(memberExpr, Expression.Constant(null)),
nullExpression,
expressionToBind
);
}
return Expression.Bind(propertyMap.DestinationProperty.MemberInfo, expressionToBind);
}
}
return Expression.Bind(propertyMap.DestinationProperty.MemberInfo,
Expression.Convert(result.ResolutionExpression, propertyMap.DestinationPropertyType));
}
示例2: BindEnumerableExpression
private static MemberAssignment BindEnumerableExpression(IConfigurationProvider configuration, PropertyMap propertyMap, ExpressionRequest request, ExpressionResolutionResult result, ConcurrentDictionary<ExpressionRequest, int> typePairCount)
{
var destinationListType = TypeHelper.GetElementType(propertyMap.DestinationPropertyType);
var sourceListType = TypeHelper.GetElementType(propertyMap.SourceType);
var expression = result.ResolutionExpression;
if (sourceListType != destinationListType)
{
var listTypePair = new ExpressionRequest(sourceListType, destinationListType, request.MembersToExpand);
var transformedExpression = configuration.ExpressionBuilder.CreateMapExpression(listTypePair, typePairCount);
if(transformedExpression == null)
{
return null;
}
expression = Expression.Call(typeof (Enumerable), "Select", new[] {sourceListType, destinationListType}, result.ResolutionExpression, transformedExpression);
}
expression = Expression.Call(typeof(Enumerable), propertyMap.DestinationPropertyType.IsArray ? "ToArray" : "ToList", new[] { destinationListType }, expression);
if(configuration.Configuration.AllowNullCollections) {
expression = Expression.Condition(
Expression.NotEqual(
Expression.TypeAs(result.ResolutionExpression, typeof(object)),
Expression.Constant(null)),
expression,
Expression.Constant(null, propertyMap.DestinationPropertyType));
}
return Expression.Bind(propertyMap.DestinationProperty, expression);
}
示例3: BindEnumerableExpression
private static MemberAssignment BindEnumerableExpression(IMappingEngine mappingEngine, PropertyMap propertyMap,
ExpressionRequest request, ExpressionResolutionResult result,
Internal.IDictionary<ExpressionRequest, int> typePairCount)
{
MemberAssignment bindExpression;
Type destinationListType = GetDestinationListTypeFor(propertyMap);
Type sourceListType = null;
// is list
if (result.Type.IsArray)
{
sourceListType = result.Type.GetElementType();
}
else
{
sourceListType = result.Type.GetGenericArguments().First();
}
var listTypePair = new ExpressionRequest(sourceListType, destinationListType, request.IncludedMembers);
var selectExpression = result.ResolutionExpression;
if (sourceListType != destinationListType)
{
var transformedExpression = Extensions.CreateMapExpression(mappingEngine, listTypePair, typePairCount);
selectExpression = Expression.Call(
typeof (Enumerable),
"Select",
new[] {sourceListType, destinationListType},
result.ResolutionExpression,
transformedExpression);
}
if (typeof (IList<>).MakeGenericType(destinationListType)
.IsAssignableFrom(propertyMap.DestinationPropertyType)
||
typeof (ICollection<>).MakeGenericType(destinationListType)
.IsAssignableFrom(propertyMap.DestinationPropertyType))
{
// Call .ToList() on IEnumerable
var toListCallExpression = GetToListCallExpression(propertyMap, destinationListType, selectExpression);
bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, toListCallExpression);
}
else if (propertyMap.DestinationPropertyType.IsArray)
{
// Call .ToArray() on IEnumerable
MethodCallExpression toArrayCallExpression = Expression.Call(
typeof (Enumerable),
"ToArray",
new[] {destinationListType},
selectExpression);
bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, toArrayCallExpression);
}
else
{
// destination type implements ienumerable, but is not an ilist. allow deferred enumeration
bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, selectExpression);
}
return bindExpression;
}
示例4: BindCustomProjectionExpression
private static MemberAssignment BindCustomProjectionExpression(PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionResolutionResult result)
{
var visitor = new ParameterReplacementVisitor(result.ResolutionExpression);
var replaced = visitor.Visit(propertyTypeMap.CustomProjection.Body);
return Expression.Bind(propertyMap.DestinationProperty.MemberInfo, replaced);
}
示例5: ExpressionResolutionResult
private static ExpressionResolutionResult ExpressionResolutionResult(
ExpressionResolutionResult expressionResolutionResult, LambdaExpression lambdaExpression)
{
Expression currentChild = lambdaExpression.ReplaceParameters(expressionResolutionResult.ResolutionExpression);
Type currentChildType = currentChild.Type;
return new ExpressionResolutionResult(currentChild, currentChildType);
}
示例6: BindEnumerableExpression
private static MemberAssignment BindEnumerableExpression(IConfigurationProvider configuration, PropertyMap propertyMap, ExpressionRequest request, ExpressionResolutionResult result, ConcurrentDictionary<ExpressionRequest, int> typePairCount)
{
var destinationListType = GetDestinationListTypeFor(propertyMap);
var sourceListType = result.Type.IsArray ? result.Type.GetElementType() : result.Type.GetTypeInfo().GenericTypeArguments.First();
var listTypePair = new ExpressionRequest(sourceListType, destinationListType, request.MembersToExpand);
Expression exp = result.ResolutionExpression;
if (sourceListType != destinationListType)
{
var transformedExpression = configuration.ExpressionBuilder.CreateMapExpression(listTypePair, typePairCount);
if(transformedExpression == null)
{
return null;
}
exp = Expression.Call(
typeof (Enumerable),
"Select",
new[] {sourceListType, destinationListType},
result.ResolutionExpression,
transformedExpression);
}
if (typeof (IList<>).MakeGenericType(destinationListType)
.GetTypeInfo().IsAssignableFrom(propertyMap.DestinationPropertyType.GetTypeInfo())
||
typeof (ICollection<>).MakeGenericType(destinationListType)
.GetTypeInfo().IsAssignableFrom(propertyMap.DestinationPropertyType.GetTypeInfo()))
{
// Call .ToList() on IEnumerable
exp = GetToListCallExpression(propertyMap, destinationListType, exp);
}
else if (propertyMap.DestinationPropertyType.IsArray)
{
// Call .ToArray() on IEnumerable
exp = Expression.Call(
typeof (Enumerable),
"ToArray",
new[] {destinationListType},
exp);
}
if(configuration.AllowNullCollections) {
exp = Expression.Condition(
Expression.NotEqual(
Expression.TypeAs(result.ResolutionExpression, typeof(object)),
Expression.Constant(null)),
exp,
Expression.Constant(null, propertyMap.DestinationPropertyType));
}
return Expression.Bind(propertyMap.DestinationProperty.MemberInfo, exp);
}
示例7: ExpressionResolutionResult
private static ExpressionResolutionResult ExpressionResolutionResult(
ExpressionResolutionResult expressionResolutionResult, LambdaExpression lambdaExpression)
{
var oldParameter = lambdaExpression.Parameters.Single();
var newParameter = expressionResolutionResult.ResolutionExpression;
var converter = new ParameterConversionVisitor(newParameter, oldParameter);
Expression currentChild = converter.Visit(lambdaExpression.Body);
Type currentChildType = currentChild.Type;
return new ExpressionResolutionResult(currentChild, currentChildType);
}
示例8: BindEnumerableExpression
private static MemberAssignment BindEnumerableExpression(IConfigurationProvider configuration, PropertyMap propertyMap, ExpressionRequest request, ExpressionResolutionResult result, ConcurrentDictionary<ExpressionRequest, int> typePairCount)
{
MemberAssignment bindExpression;
Type destinationListType = GetDestinationListTypeFor(propertyMap);
var sourceListType = result.Type.IsArray ? result.Type.GetElementType() : result.Type.GetTypeInfo().GenericTypeArguments.First();
var listTypePair = new ExpressionRequest(sourceListType, destinationListType, request.MembersToExpand);
var selectExpression = result.ResolutionExpression;
if (sourceListType != destinationListType)
{
var transformedExpression = configuration.ExpressionBuilder.CreateMapExpression(listTypePair, typePairCount);
if(transformedExpression == null)
{
return null;
}
selectExpression = Expression.Call(
typeof (Enumerable),
"Select",
new[] {sourceListType, destinationListType},
result.ResolutionExpression,
transformedExpression);
}
if (typeof (IList<>).MakeGenericType(destinationListType)
.GetTypeInfo().IsAssignableFrom(propertyMap.DestinationPropertyType.GetTypeInfo())
||
typeof (ICollection<>).MakeGenericType(destinationListType)
.GetTypeInfo().IsAssignableFrom(propertyMap.DestinationPropertyType.GetTypeInfo()))
{
// Call .ToList() on IEnumerable
var toListCallExpression = GetToListCallExpression(propertyMap, destinationListType, selectExpression);
bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, toListCallExpression);
}
else if (propertyMap.DestinationPropertyType.IsArray)
{
// Call .ToArray() on IEnumerable
MethodCallExpression toArrayCallExpression = Expression.Call(
typeof (Enumerable),
"ToArray",
new[] {destinationListType},
selectExpression);
bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, toArrayCallExpression);
}
else
{
// destination type implements ienumerable, but is not an ilist. allow deferred enumeration
bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, selectExpression);
}
return bindExpression;
}
示例9: ExpressionResolutionResult
private static ExpressionResolutionResult ExpressionResolutionResult(
ExpressionResolutionResult expressionResolutionResult, MemberInfo getter)
{
Expression currentChild = expressionResolutionResult.ResolutionExpression;
Type currentChildType;
var propertyInfo = getter as PropertyInfo;
if (propertyInfo != null)
{
currentChild = Expression.Property(currentChild, propertyInfo);
currentChildType = propertyInfo.PropertyType;
}
else
currentChildType = currentChild.Type;
return new ExpressionResolutionResult(currentChild, currentChildType);
}
示例10: BindMappedTypeExpression
private static MemberAssignment BindMappedTypeExpression(IMappingEngine mappingEngine, PropertyMap propertyMap,
ExpressionRequest request, ExpressionResolutionResult result, Internal.IDictionary<ExpressionRequest, int> typePairCount)
{
var transformedExpression = ((IMappingEngineRunner)mappingEngine).CreateMapExpression(request, result.ResolutionExpression, typePairCount);
// Handles null source property so it will not create an object with possible non-nullable propeerties
// which would result in an exception.
if (mappingEngine.ConfigurationProvider.MapNullSourceValuesAsNull)
{
var expressionNull = Expression.Constant(null, propertyMap.DestinationPropertyType);
transformedExpression =
Expression.Condition(Expression.NotEqual(result.ResolutionExpression, Expression.Constant(null)),
transformedExpression, expressionNull);
}
return Expression.Bind(propertyMap.DestinationProperty.MemberInfo, transformedExpression);
}
示例11: GetExpressionResolutionResult
public ExpressionResolutionResult GetExpressionResolutionResult(ExpressionResolutionResult expressionResolutionResult, PropertyMap propertyMap, IValueResolver valueResolver)
{
Expression currentChild = expressionResolutionResult.ResolutionExpression;
Type currentChildType;
var getter = (IMemberGetter)valueResolver;
var memberInfo = getter.MemberInfo;
var propertyInfo = memberInfo as PropertyInfo;
if (propertyInfo != null)
{
currentChild = Expression.Property(currentChild, propertyInfo);
currentChildType = propertyInfo.PropertyType;
}
else
currentChildType = currentChild.Type;
return new ExpressionResolutionResult(currentChild, currentChildType);
}
示例12: BindMappedTypeExpression
private static MemberAssignment BindMappedTypeExpression(IConfigurationProvider configuration, PropertyMap propertyMap, ExpressionRequest request, ExpressionResolutionResult result, IDictionary<ExpressionRequest, int> typePairCount)
{
var transformedExpression = configuration.ExpressionBuilder.CreateMapExpression(request, result.ResolutionExpression, typePairCount);
if(transformedExpression == null)
{
return null;
}
// Handles null source property so it will not create an object with possible non-nullable propeerties
// which would result in an exception.
if (propertyMap.TypeMap.Profile.AllowNullDestinationValues && !propertyMap.AllowNull)
{
var expressionNull = Expression.Constant(null, propertyMap.DestinationPropertyType);
transformedExpression =
Expression.Condition(Expression.NotEqual(result.ResolutionExpression, Expression.Constant(null)),
transformedExpression, expressionNull);
}
return Expression.Bind(propertyMap.DestinationProperty, transformedExpression);
}
示例13: CanGetExpressionResolutionResult
public bool CanGetExpressionResolutionResult(ExpressionResolutionResult expressionResolutionResult, IValueResolver valueResolver)
{
return valueResolver is IMemberGetter;
}
示例14: BindCustomProjectionExpression
private static MemberAssignment BindCustomProjectionExpression(PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionResolutionResult result)
{
return Expression.Bind(propertyMap.DestinationProperty, propertyTypeMap.CustomProjection.ConvertReplaceParameters(result.ResolutionExpression));
}
示例15: IsMatch
public bool IsMatch(PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionResolutionResult result)
{
return PrimitiveExtensions.IsNullableType(propertyMap.DestinationPropertyType)
&& !PrimitiveExtensions.IsNullableType(result.Type);
}