本文整理汇总了C#中PropertyMap类的典型用法代码示例。如果您正苦于以下问题:C# PropertyMap类的具体用法?C# PropertyMap怎么用?C# PropertyMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertyMap类属于命名空间,在下文中一共展示了PropertyMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapExpression
public Expression MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider,
PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
{
Expression<Func<DestinationType>> expr = () => new DestinationType();
return expr.Body;
}
示例2: AutoMapperMappingException
public AutoMapperMappingException(ResolutionContext context, Exception inner, PropertyMap propertyMap)
: base(null, inner)
{
Context = context;
Types = context.Types;
PropertyMap = propertyMap;
}
示例3: NewInstance
/// <summary>
/// Static function to return new instance of map schema
/// </summary>
/// <param name="jtok">JSON object for the map schema</param>
/// <param name="names">list of named schemas already read</param>
/// <param name="encspace">enclosing namespace of the map schema</param>
/// <returns></returns>
internal static MapSchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
{
JToken jvalue = jtok["values"];
if (null == jvalue) throw new AvroTypeException("Map does not have 'values'");
return new MapSchema(Schema.ParseJson(jvalue, names, encspace), props);
}
示例4: 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);
}
示例5: NewInstance
/// <summary>
/// Static function to return new instance of the fixed schema class
/// </summary>
/// <param name="jtok">JSON object for the fixed schema</param>
/// <param name="names">list of named schema already parsed in</param>
/// <param name="encspace">enclosing namespace of the fixed schema</param>
/// <returns></returns>
internal static FixedSchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
{
SchemaName name = NamedSchema.GetName(jtok, encspace);
var aliases = NamedSchema.GetAliases(jtok, name.Space, name.EncSpace);
return new FixedSchema(name, aliases, JsonHelper.GetRequiredInteger(jtok, "size"), props, names);
}
示例6: MapExpression
public Expression MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider,
PropertyMap propertyMap, Expression sourceExpression, Expression destExpression,
Expression contextExpression)
=>
typeMapRegistry.MapCollectionExpression(configurationProvider, propertyMap, sourceExpression, destExpression,
contextExpression, CollectionMapperExtensions.IfNotNull, typeof(Dictionary<,>),
CollectionMapperExtensions.MapItemExpr);
示例7: FixedSchema
/// <summary>
/// Constructor
/// </summary>
/// <param name="name">name of the fixed schema</param>
/// <param name="aliases">list of aliases for the name</param>
/// <param name="size">fixed size</param>
/// <param name="names">list of named schema already parsed in</param>
private FixedSchema(SchemaName name, IList<SchemaName> aliases, int size, PropertyMap props, SchemaNames names)
: base(Type.Fixed, name, aliases, props, names)
{
if (null == name.Name) throw new SchemaParseException("name cannot be null for fixed schema.");
if (size <= 0) throw new ArgumentOutOfRangeException("size", "size must be greater than zero.");
this.Size = size;
}
示例8: NewInstance
/// <summary>
/// Static class to return a new instance of ArraySchema
/// </summary>
/// <param name="jtok">JSON object for the array schema</param>
/// <param name="names">list of named schemas already parsed</param>
/// <param name="encspace">enclosing namespace for the array schema</param>
/// <returns></returns>
internal static ArraySchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
{
JToken jitem = jtok["items"];
if (null == jitem) throw new AvroTypeException("Array does not have 'items'");
return new ArraySchema(Schema.ParseJson(jitem, names, encspace), props);
}
示例9: 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));
}
示例10: UnionSchema
/// <summary>
/// Contructor for union schema
/// </summary>
/// <param name="schemas"></param>
private UnionSchema(List<Schema> schemas, PropertyMap props)
: base(Type.Union, props)
{
if (schemas == null)
throw new ArgumentNullException("schemas");
this.Schemas = schemas;
}
示例11: NewInstance
/// <summary>
/// Static function to return new instance of primitive schema
/// </summary>
/// <param name="type">primitive type</param>
/// <returns></returns>
public static PrimitiveSchema NewInstance(string type, PropertyMap props = null)
{
const string q = "\"";
if (type.StartsWith(q) && type.EndsWith(q)) type = type.Substring(1, type.Length - 2);
switch (type)
{
case "null":
return new PrimitiveSchema(Schema.Type.Null, props);
case "boolean":
return new PrimitiveSchema(Schema.Type.Boolean, props);
case "int":
return new PrimitiveSchema(Schema.Type.Int, props);
case "long":
return new PrimitiveSchema(Schema.Type.Long, props);
case "float":
return new PrimitiveSchema(Schema.Type.Float, props);
case "double":
return new PrimitiveSchema(Schema.Type.Double, props);
case "bytes":
return new PrimitiveSchema(Schema.Type.Bytes, props);
case "string":
return new PrimitiveSchema(Schema.Type.String, props);
default:
return null;
}
}
示例12: GetDestinationListTypeFor
private static Type GetDestinationListTypeFor(PropertyMap propertyMap)
{
var destinationListType = propertyMap.DestinationPropertyType.IsArray
? propertyMap.DestinationPropertyType.GetElementType()
: propertyMap.DestinationPropertyType.GetGenericArguments().First();
return destinationListType;
}
示例13: 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;
}
示例14: MapExpression
public Expression MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
{
var listType = typeof(List<>).MakeGenericType(TypeHelper.GetElementType(destExpression.Type));
var list = typeMapRegistry.MapCollectionExpression(configurationProvider, propertyMap, sourceExpression, Default(listType), contextExpression, _ => Constant(false), typeof(List<>), CollectionMapperExtensions.MapItemExpr);
var dest = Variable(listType, "dest");
return Block(new[] { dest }, Assign(dest, list), Condition(NotEqual(dest, Default(listType)), New(destExpression.Type.GetConstructors().First(), dest), Default(destExpression.Type)));
}
示例15: 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);
}