/// <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; }
/// <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); }
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)); }
private static Type GetDestinationListTypeFor(PropertyMap propertyMap) { var destinationListType = propertyMap.DestinationPropertyType.IsArray ? propertyMap.DestinationPropertyType.GetElementType() : propertyMap.DestinationPropertyType.GetGenericArguments().First(); return destinationListType; }
/// <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); }
/// <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; } }
/// <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); }
public Expression MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression) { Expression<Func<DestinationType>> expr = () => new DestinationType(); return expr.Body; }
public AutoMapperMappingException(ResolutionContext context, Exception inner, PropertyMap propertyMap) : base(null, inner) { Context = context; Types = context.Types; PropertyMap = propertyMap; }
/// <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; }
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);
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); }
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; }
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); }
public void Initialize() { context = new FileContext("test", new MemoryStream()); fieldMock = new Mock<IField<FileContext, int>>(); map = new PropertyMap<Target, int, FileContext, int>(t => t.Id, fieldMock.Object, i => i); target = new Target(); }
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))); }
public Expression MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression) { return Condition(Equal(sourceExpression, Default(sourceExpression.Type)), Constant(null, typeof(string)), Call(sourceExpression, typeof(object).GetDeclaredMethod("ToString"))); }
/// <summary> /// Constructor for enum schema /// </summary> /// <param name="name">name of enum</param> /// <param name="aliases">list of aliases for the name</param> /// <param name="symbols">list of enum symbols</param> /// <param name="symbolMap">map of enum symbols and value</param> /// <param name="names">list of named schema already read</param> private EnumSchema(SchemaName name, IList<SchemaName> aliases, List<string> symbols, IDictionary<String, int> symbolMap, PropertyMap props, SchemaNames names) : base(Type.Enumeration, name, aliases, props, names) { if (null == name.Name) throw new SchemaParseException("name cannot be null for enum schema."); this.Symbols = symbols; this.symbolMap = symbolMap; }
public PropertyMap getProperties() { PropertyMap map = new PropertyMap(); Dictionary<string, string>.Enumerator enumer = propertyMap.GetEnumerator(); while(enumer.MoveNext()){ map.Add(enumer.Current.Key, enumer.Current.Value); } return map; }
private static MethodCallExpression GetToListCallExpression(PropertyMap propertyMap, Type destinationListType, Expression selectExpression) { return Expression.Call( typeof (Enumerable), propertyMap.DestinationPropertyType.IsArray ? "ToArray" : "ToList", new[] {destinationListType}, selectExpression); }
/// <summary> /// Constructor for named schema class /// </summary> /// <param name="type">schema type</param> /// <param name="name">name</param> /// <param name="names">list of named schemas already read</param> protected NamedSchema(Type type, SchemaName name, IList<SchemaName> aliases, PropertyMap props, SchemaNames names) : base(type, props) { this.SchemaName = name; this.aliases = aliases; if (null != name.Name) // Added this check for anonymous records inside Message if (!names.Add(name, this)) throw new AvroException("Duplicate schema name " + name.Fullname); }
public Expression MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression) { var listType = typeof(List<>).MakeGenericType(TypeHelper.GetElementType(destExpression.Type)); return typeMapRegistry.MapCollectionExpression(configurationProvider, propertyMap, sourceExpression, Expression.Default(listType), contextExpression, IfEditableList, typeof(List<>), CollectionMapperExtensions.MapItemExpr); }
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); }
internal static Expression MapItemExpr(this TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, PropertyMap propertyMap, Type sourceType, Type destType, ParameterExpression itemParam, Expression contextParam) { var sourceElementType = TypeHelper.GetElementType(sourceType); var destElementType = TypeHelper.GetElementType(destType); var typePair = new TypePair(sourceElementType, destElementType); var itemExpr = TypeMapPlanBuilder.MapExpression(typeMapRegistry, configurationProvider, typePair, itemParam, contextParam, propertyMap); return itemExpr; }
public Expression MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression) { var toStringCall = Call(sourceExpression, typeof(object).GetDeclaredMethod("ToString")); if(sourceExpression.Type.IsValueType()) { return toStringCall; } return Condition(Equal(sourceExpression, Constant(null)), Constant(null, typeof(string)), toStringCall); }
public void PropertyMap_GoodValues_Succeeds() { //Arrange var propertyInfo = ReflectionHelper.GetMemberInfo<string, int>((string s) => s.Length) as PropertyInfo; //Act var propertyMap = new PropertyMap(propertyInfo); //Assert Assert.AreEqual<string>("Length", propertyMap.SourcePropertyInfo.Name); }
public void ToString_Always_Succeeds() { //Arrange var propertyInfo = ReflectionHelper.GetMemberInfo<string, int>((string s) => s.Length) as PropertyInfo; //Act var propertyMap = new PropertyMap(propertyInfo); //Assert string actual = propertyMap.ToString(); Assert.AreEqual<string>(string.Format("{{{0}, {1}}}", propertyInfo.Name, propertyInfo.ReflectedType), actual); }
public ColumnSqlBuilder(Column column, TypeMap typeMap, PropertyMap propertyMap, Func<string, string> nameConverter) { Require.IsNotNull(column, "Не задан столбец таблицы для построения SQL-выражения"); Require.IsNotNull(typeMap, "Не задан мэппинг типов данных"); Require.IsNotNull(propertyMap, "Не задан мэппинг свойств столбца таблицы"); Require.IsNotNull(nameConverter, "Не задан конвертер имени столбца таблицы"); this.column = column; this.typeMap = typeMap; this.propertyMap = propertyMap; this.nameConverter = nameConverter; }
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; }
public void Image_SET_VALUE_After_Set_something() { /* TEST CODE */ ImageView testView = new ImageView(); string resultString = ""; bool resultBool = false; using (PropertyMap map = testView.Image) { bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString); Assert.AreEqual(false, ret, "map don't have ResourceUrl"); ret = map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false; Assert.AreEqual(false, ret, "map don't have AlphaMaskURL"); ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false; Assert.AreEqual(false, ret, "map don't have CropToMask"); ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false; Assert.AreEqual(false, ret, "map don't have SynchronousLoading"); } string testUrl1 = "test1"; string testUrl2 = "test2"; testView.ResourceUrl = testUrl1; testView.AlphaMaskURL = testUrl2; testView.CropToMask = true; testView.SynchronousLoading = true; using (PropertyMap map = testView.Image) { bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString); Assert.AreEqual(true, ret, "map must have ResourceUrl"); Assert.AreEqual(testUrl1, resultString, "...and That value must be equal what we added"); ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString); Assert.AreEqual(true, ret, "map must have AlphaMaskURL"); Assert.AreEqual(testUrl2, resultString, "...and That value must be equal what we added"); ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false; Assert.AreEqual(true, ret, "map must have CropToMask"); Assert.AreEqual(true, resultBool, "...and That value must be equal what we added"); ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false; Assert.AreEqual(true, ret, "map must have SynchronousLoading"); Assert.AreEqual(true, resultBool, "...and That value must be equal what we added"); } // Update Image map by PropertyMap. // Cached property map will be overwrited. using (PropertyMap setImageMap = new PropertyMap()) { setImageMap[ImageVisualProperty.URL] = new PropertyValue(image_path); setImageMap[ImageVisualProperty.AlphaMaskURL] = new PropertyValue(mask_path); setImageMap[ImageVisualProperty.CropToMask] = new PropertyValue(false); setImageMap[ImageVisualProperty.SynchronousLoading] = new PropertyValue(false); testView.Image = setImageMap; } using (PropertyMap map = testView.Image) { bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString); Assert.AreEqual(true, ret, "map must have ResourceUrl"); Assert.AreEqual(image_path, resultString, "...and That value must be equal what we added"); ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString); Assert.AreEqual(true, ret, "map must have AlphaMaskURL"); Assert.AreEqual(mask_path, resultString, "...and That value must be equal what we added"); ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false; Assert.AreEqual(true, ret, "map must have CropToMask"); Assert.AreEqual(false, resultBool, "...and That value must be equal what we added"); ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false; Assert.AreEqual(true, ret, "map must have SynchronousLoading"); Assert.AreEqual(false, resultBool, "...and That value must be equal what we added"); } }
public void CreateDepthLayout() { mDepthLayout = new PropertyMap(); mDepthLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.DEPTH)); }
public bool CanGetExpressionResolutionResult(ExpressionResolutionResult expressionResolutionResult, PropertyMap propertyMap) { return(propertyMap.CustomExpression != null); }
public static Expression MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, TypePair typePair, Expression sourceParameter, Expression contextParameter, PropertyMap propertyMap = null, Expression destinationParameter = null) { if (destinationParameter == null) { destinationParameter = Default(typePair.DestinationType); } var typeMap = configurationProvider.ResolveTypeMap(typePair); if (typeMap != null) { if (!typeMap.HasDerivedTypesToInclude()) { typeMap.Seal(typeMapRegistry, configurationProvider); if (typeMap.MapExpression != null) { return(typeMap.MapExpression.ConvertReplaceParameters(sourceParameter, destinationParameter, contextParameter)); } else { return(ContextMap(typePair, sourceParameter, contextParameter, destinationParameter)); } } else { return(ContextMap(typePair, sourceParameter, contextParameter, destinationParameter)); } } var match = configurationProvider.GetMappers().FirstOrDefault(m => m.IsMatch(typePair)); if (match != null) { var mapperExpression = match.MapExpression(typeMapRegistry, configurationProvider, propertyMap, sourceParameter, destinationParameter, contextParameter); return(ToType(mapperExpression, typePair.DestinationType)); } return(ContextMap(typePair, sourceParameter, contextParameter, destinationParameter)); }
private PropertyMap CreateDistanceFieldEffect() { string fragmentShaderPrefix = "#extension GL_OES_standard_derivatives : enable\n"; string fragmentShader = "varying mediump vec2 vTexCoord;\n" + "\n" + "uniform mediump float uGlowBoundary;\n" + "uniform mediump vec2 uOutlineParams;\n" + "uniform lowp vec4 uOutlineColor;\n" + "uniform lowp vec4 uShadowColor;\n" + "uniform mediump vec2 uShadowOffset;\n" + "uniform lowp vec4 uGlowColor;\n" + "uniform lowp float uDoOutline;\n" + "uniform lowp float uDoShadow;\n" + "uniform lowp float uDoGlow;\n" + "\n" + "uniform sampler2D sTexture;\n" + "uniform lowp vec4 uColor;\n" + "\n" + "void main()\n" + "{\n" + "// sample distance field\n" + "mediump float smoothing = 0.5;\n" + "mediump float distance = texture2D(sTexture, vTexCoord).a;\n" + "mediump float smoothWidth = fwidth(distance);\n" + "mediump float alphaFactor = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);\n" + "lowp vec4 color;\n" + "if (uDoShadow == 0.0)\n" + "{\n" + "mediump float alpha = uColor.a * alphaFactor;\n" + "lowp vec4 rgb = uColor;\n" + "\n" + "if (uDoOutline > 0.0)\n" + "{\n" + "mediump float outlineWidth = uOutlineParams[1] + smoothWidth;\n" + "mediump float outlineBlend = smoothstep(uOutlineParams[0] - outlineWidth, uOutlineParams[0] + outlineWidth, distance);\n" + "alpha = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);\n" + "rgb = mix(uOutlineColor, uColor, outlineBlend);\n" + "}\n" + "\n" + "if (uDoGlow > 0.0)\n" + "{\n" + "rgb = mix(uGlowColor, rgb, alphaFactor);\n" + "alpha = smoothstep(uGlowBoundary, smoothing, distance);\n" + "}\n" + "\n" + "// set fragment color\n" + "color = vec4(rgb.rgb, alpha);\n" + "}\n" + "\n" + "else // (uDoShadow > 0.0)\n" + "{\n" + "mediump float shadowDistance = texture2D(sTexture, vTexCoord - uShadowOffset).a;\n" + "mediump float inText = alphaFactor;\n" + "mediump float inShadow = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, shadowDistance);\n" + "\n" + "// inside object, outside shadow\n" + "if (inText == 1.0)\n" + "{\n" + "color = uColor;\n" + "}\n" + "// inside object, outside shadow\n" + "else if ((inText != 0.0) && (inShadow == 0.0))\n" + "{\n" + "color = uColor;\n" + "color.a *= inText;\n" + "}\n" + "// outside object, completely inside shadow\n" + "else if ((inText == 0.0) && (inShadow == 1.0))\n" + "{\n" + "color = uShadowColor;\n" + "}\n" + "// inside object, completely inside shadow\n" + "else if ((inText != 0.0) && (inShadow == 1.0))\n" + "{\n" + "color = mix(uShadowColor, uColor, inText);\n" + "color.a = uShadowColor.a;\n" + "}\n" + "// inside object, inside shadow's border\n" + "else if ((inText != 0.0) && (inShadow != 0.0))\n" + "{\n" + "color = mix(uShadowColor, uColor, inText);\n" + "color.a *= max(inText, inShadow);\n" + "}\n" + "// inside shadow's border\n" + "else if (inShadow != 0.0)\n" + "{\n" + "color = uShadowColor;\n" + "color.a *= inShadow;\n" + "}\n" + "// outside shadow and object\n" + "else \n" + "{\n" + "color.a = 0.0;\n" + "}\n" + "\n" + "}\n" + "\n" + "gl_FragColor = color;\n" + "\n" + "}"; PropertyMap map = new PropertyMap(); PropertyMap customShader = new PropertyMap(); string fragmentShaderString; fragmentShaderString = fragmentShaderPrefix + fragmentShader; customShader.Insert(Visual.ShaderProperty.FragmentShader, new PropertyValue(fragmentShaderString)); customShader.Insert(Visual.ShaderProperty.ShaderHints, new PropertyValue((int)Shader.Hint.Value.OUTPUT_IS_TRANSPARENT)); map.Insert(Visual.Property.Shader, new PropertyValue(customShader)); return(map); }
public View NewItemView(uint itemId) { // Create an image view for this item string imagePath = CommonResource.GetDaliResourcePath() + "ItemViewDemo/gallery/gallery-medium-"; uint id = itemId % 53; imagePath += id.ToString(); imagePath += ".jpg"; PropertyMap propertyMap = new PropertyMap(); propertyMap.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image)); propertyMap.Insert(ImageVisualProperty.URL, new PropertyValue(imagePath)); propertyMap.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int)VisualFittingModeType.FitKeepAspectRatio)); ImageView actor = new ImageView(); actor.Image = propertyMap; // Add a border image child actor ImageView borderActor = new ImageView(); borderActor.ParentOrigin = ParentOrigin.Center; borderActor.PivotPoint = PivotPoint.Center; borderActor.PositionUsesPivotPoint = true; borderActor.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent; borderActor.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent; borderActor.SetSizeModeFactor(new Vector3(2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f)); borderActor.SetColorMode(ColorMode.UseParentColor); PropertyMap borderProperty = new PropertyMap(); borderProperty.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Border)); borderProperty.Insert(BorderVisualProperty.Color, new PropertyValue(Color.White)); borderProperty.Insert(BorderVisualProperty.Size, new PropertyValue(ITEM_BORDER_SIZE)); borderProperty.Insert(BorderVisualProperty.AntiAliasing, new PropertyValue(true)); borderActor.Image = borderProperty; actor.Add(borderActor); Size spiralItemSize = new Size(30, 30, 0); // Add a checkbox child actor; invisible until edit-mode is enabled ImageView checkBox = new ImageView(); checkBox.Name = "CheckBox"; checkBox.SetColorMode(ColorMode.UseParentColor); checkBox.ParentOrigin = ParentOrigin.TopRight; checkBox.PivotPoint = PivotPoint.TopRight; checkBox.Size = spiralItemSize; checkBox.PositionZ = 0.1f; PropertyMap solidColorProperty = new PropertyMap(); solidColorProperty.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Color)); solidColorProperty.Insert(ColorVisualProperty.MixColor, new PropertyValue(new Color(0.0f, 0.0f, 0.0f, 0.6f))); checkBox.Image = solidColorProperty; if (Mode.MODE_REMOVE_MANY != mMode && Mode.MODE_INSERT_MANY != mMode && Mode.MODE_REPLACE_MANY != mMode) { checkBox.Hide(); } borderActor.Add(checkBox); ImageView tick = new ImageView(SELECTED_IMAGE); tick.Name = "Tick"; tick.ParentOrigin = ParentOrigin.TopRight; tick.PivotPoint = PivotPoint.TopRight; tick.Size = spiralItemSize; tick.Hide(); checkBox.Add(tick); if (mTapDetector) { mTapDetector.Attach(actor); } return(actor); }
public bool IsMatch(PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionResolutionResult result) { return(propertyMap.DestinationPropertyType.IsNullableType() && !result.Type.IsNullableType()); }
public MemberAssignment Build(IConfigurationProvider configuration, PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionRequest request, ExpressionResolutionResult result, IDictionary <ExpressionRequest, int> typePairCount, LetPropertyMaps letPropertyMaps) => BindCustomProjectionExpression(propertyMap, propertyTypeMap, result);
public void CreateSpiralLayout() { mSpiralLayout = new PropertyMap(); mSpiralLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.SPIRAL)); }
public void Image_GET_VALUE_After_Set_something() { /* TEST CODE */ ImageView testView = new ImageView(); string resultString = ""; bool resultBool = false; using (PropertyMap map = testView.Image) { bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString); Assert.AreEqual(false, ret, "map don't have ResourceUrl"); ret = map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false; Assert.AreEqual(false, ret, "map don't have AlphaMaskURL"); ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false; Assert.AreEqual(false, ret, "map don't have CropToMask"); ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false; Assert.AreEqual(false, ret, "map don't have SynchronousLoading"); } string testUrl1 = "test1"; testView.AlphaMaskURL = testUrl1; testView.CropToMask = true; testView.SynchronousLoading = true; using (PropertyMap map = testView.Image) { bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString); Assert.AreEqual(false, ret, "map don't have ResourceUrl"); ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString); Assert.AreEqual(false, ret, "map don't have AlphaMaskURL cause ResoureUrl is empty"); ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false; Assert.AreEqual(false, ret, "map don't have CropToMask cause ResoureUrl is empty"); ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false; Assert.AreEqual(false, ret, "map don't have SynchronousLoading cause ResoureUrl is empty"); } testView.ResourceUrl = image_path; using (PropertyMap map = testView.Image) { bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString); Assert.AreEqual(true, ret, "map must have ResourceUrl"); Assert.AreEqual(image_path, resultString, "...and That value must be equal what we added"); ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString); Assert.AreEqual(true, ret, "map must have AlphaMaskURL"); Assert.AreEqual(testUrl1, resultString, "...and That value must be equal what we added"); ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false; Assert.AreEqual(true, ret, "map must have CropToMask"); Assert.AreEqual(true, resultBool, "...and That value must be equal what we added"); ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false; Assert.AreEqual(true, ret, "map must have SynchronousLoading"); Assert.AreEqual(true, resultBool, "...and That value must be equal what we added"); } // Insert empty resource Url testView.ResourceUrl = ""; using (PropertyMap map = testView.Image) { bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString); Assert.AreEqual(false, ret, "map don't have ResourceUrl"); ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString); Assert.AreEqual(false, ret, "map don't have AlphaMaskURL cause ResoureUrl is empty"); ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false; Assert.AreEqual(false, ret, "map don't have CropToMask cause ResoureUrl is empty"); ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false; Assert.AreEqual(false, ret, "map don't have SynchronousLoading cause ResoureUrl is empty"); } // Insert valid resource Url testView.ResourceUrl = mask_path; using (PropertyMap map = testView.Image) { bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString); Assert.AreEqual(true, ret, "map must have ResourceUrl"); Assert.AreEqual(mask_path, resultString, "...and That value must be equal what we added"); ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString); Assert.AreEqual(true, ret, "map must have AlphaMaskURL"); Assert.AreEqual(testUrl1, resultString, "...and That value must be equal what we added"); ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false; Assert.AreEqual(true, ret, "map must have CropToMask"); Assert.AreEqual(true, resultBool, "...and That value must be equal what we added"); ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false; Assert.AreEqual(true, ret, "map must have SynchronousLoading"); Assert.AreEqual(true, resultBool, "...and That value must be equal what we added"); } testView.Dispose(); }
public static Expression MapItemExpr(IConfigurationProvider configurationProvider, ProfileMap profileMap, PropertyMap propertyMap, Type sourceType, Type destType, Expression contextParam, out ParameterExpression itemParam) { var sourceElementType = ElementTypeHelper.GetElementType(sourceType); var destElementType = ElementTypeHelper.GetElementType(destType); itemParam = Parameter(sourceElementType, "item"); var typePair = new TypePair(sourceElementType, destElementType); var itemExpr = TypeMapPlanBuilder.MapExpression(configurationProvider, profileMap, typePair, itemParam, contextParam, propertyMap); return(ToType(itemExpr, destElementType)); }
public static Expression MapCollectionExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression, Func <Expression, Expression> conditionalExpression, Type ifInterfaceType, MapItem mapItem) { var passedDestination = Variable(destExpression.Type, "passedDestination"); var condition = conditionalExpression(passedDestination); var newExpression = Variable(passedDestination.Type, "collectionDestination"); var sourceElementType = ElementTypeHelper.GetElementType(sourceExpression.Type); var itemExpr = mapItem(configurationProvider, profileMap, propertyMap, sourceExpression.Type, passedDestination.Type, contextExpression, out ParameterExpression itemParam); var destinationElementType = itemExpr.Type; var destinationCollectionType = typeof(ICollection <>).MakeGenericType(destinationElementType); if (!destinationCollectionType.IsAssignableFrom(destExpression.Type)) { destinationCollectionType = typeof(IList); } var addMethod = destinationCollectionType.GetDeclaredMethod("Add"); var destination = propertyMap?.UseDestinationValue == true ? passedDestination : newExpression; var addItems = ForEach(sourceExpression, itemParam, Call(destination, addMethod, itemExpr)); var mapExpr = Block(addItems, destination); var clearMethod = destinationCollectionType.GetDeclaredMethod("Clear"); var checkNull = Block(new[] { newExpression, passedDestination }, Assign(passedDestination, destExpression), IfThenElse(condition ?? Constant(false), Block(Assign(newExpression, passedDestination), Call(newExpression, clearMethod)), Assign(newExpression, passedDestination.Type.NewExpr(ifInterfaceType))), ToType(mapExpr, passedDestination.Type) ); if (propertyMap != null) { return(checkNull); } var elementTypeMap = configurationProvider.ResolveTypeMap(sourceElementType, destinationElementType); if (elementTypeMap == null) { return(checkNull); } var checkContext = TypeMapPlanBuilder.CheckContext(elementTypeMap, contextExpression); if (checkContext == null) { return(checkNull); } return(Block(checkContext, checkNull)); }
public void CreateGridLayout() { mGridLayout = new PropertyMap(); mGridLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.GRID)); }
public MemberAssignment Build(IConfigurationProvider configuration, PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionRequest request, ExpressionResolutionResult result, ConcurrentDictionary <ExpressionRequest, int> typePairCount) { return(BindNullableExpression(propertyMap, result)); }
public Expression MapExpression(TypePair typePair, Expression sourceParameter, PropertyMap propertyMap = null, Expression destinationParameter = null) { return(MapExpression(_typeMapRegistry, _configurationProvider, typePair, sourceParameter, _context, propertyMap, destinationParameter)); }
public ExpressionResolutionResult GetExpressionResolutionResult( ExpressionResolutionResult expressionResolutionResult, PropertyMap propertyMap) { return(ExpressionResolutionResult(expressionResolutionResult, propertyMap.CustomExpression)); }
private Expression BuildValueResolverFunc(PropertyMap propertyMap, Expression destValueExpr) { Expression valueResolverFunc; var destinationPropertyType = propertyMap.DestinationPropertyType; var valueResolverConfig = propertyMap.ValueResolverConfig; var typeMap = propertyMap.TypeMap; if (valueResolverConfig != null) { valueResolverFunc = ToType(BuildResolveCall(destValueExpr, valueResolverConfig), destinationPropertyType); } else if (propertyMap.CustomResolver != null) { valueResolverFunc = propertyMap.CustomResolver.ConvertReplaceParameters(_source, _destination, destValueExpr, _context); } else if (propertyMap.CustomExpression != null) { var nullCheckedExpression = propertyMap.CustomExpression.ReplaceParameters(_source).IfNotNull(destinationPropertyType); var destinationNullable = destinationPropertyType.IsNullableType(); var returnType = destinationNullable && destinationPropertyType.GetTypeOfNullable() == nullCheckedExpression.Type ? destinationPropertyType : nullCheckedExpression.Type; valueResolverFunc = TryCatch( ToType(nullCheckedExpression, returnType), Catch(typeof(NullReferenceException), Default(returnType)), Catch(typeof(ArgumentNullException), Default(returnType)) ); } else if (propertyMap.SourceMembers.Any() && propertyMap.SourceType != null ) { var last = propertyMap.SourceMembers.Last(); var pi = last as PropertyInfo; if (pi != null && pi.GetGetMethod(true) == null) { valueResolverFunc = Default(last.GetMemberType()); } else { valueResolverFunc = propertyMap.SourceMembers.Aggregate( (Expression)_source, (inner, getter) => getter is MethodInfo ? getter.IsStatic() ? Call(null, (MethodInfo)getter, inner) : (Expression)Call(inner, (MethodInfo)getter) : MakeMemberAccess(getter.IsStatic() ? null : inner, getter) ); valueResolverFunc = valueResolverFunc.IfNotNull(destinationPropertyType); } } else if (propertyMap.SourceMember != null) { valueResolverFunc = MakeMemberAccess(_source, propertyMap.SourceMember); } else { valueResolverFunc = Throw(Constant(new Exception("I done blowed up"))); } if (propertyMap.NullSubstitute != null) { var nullSubstitute = Constant(propertyMap.NullSubstitute); valueResolverFunc = Coalesce(valueResolverFunc, ToType(nullSubstitute, valueResolverFunc.Type)); } else if (!typeMap.Profile.AllowNullDestinationValues) { var toCreate = propertyMap.SourceType ?? destinationPropertyType; if (!toCreate.IsAbstract() && toCreate.IsClass()) { valueResolverFunc = Coalesce( valueResolverFunc, ToType(Call( typeof(ObjectCreator).GetDeclaredMethod("CreateNonNullValue"), Constant(toCreate) ), propertyMap.SourceType)); } } return(valueResolverFunc); }
private void MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, object mappedObject, PropertyMap propertyMap) { if (propertyMap.CanResolveValue()) { if (!propertyMap.ShouldAssignValue(context.CreateMemberContext(null, null, null, null, propertyMap))) { return; } object destinationValue = null; ResolutionResult result; try { result = propertyMap.ResolveValue(context); } catch (MapperMappingException) { throw; } catch (Exception ex) { var errorContext = CreateErrorContext(context, propertyMap, destinationValue); throw new MapperMappingException(errorContext, ex); } if (result.ShouldIgnore) { return; } if (propertyMap.UseDestinationValue) { destinationValue = propertyMap.DestinationProperty.GetValue(mappedObject); } var sourceType = result.Type; var destinationType = propertyMap.DestinationProperty.MemberType; var typeMap = mapper.ConfigurationProvider.FindTypeMapFor(result, destinationType); Type targetSourceType = typeMap != null ? typeMap.SourceType : sourceType; var newContext = context.CreateMemberContext(typeMap, result.Value, destinationValue, targetSourceType, propertyMap); try { object propertyValueToAssign = mapper.Map(newContext); AssignValue(propertyMap, mappedObject, propertyValueToAssign); } catch (MapperMappingException) { throw; } catch (Exception ex) { throw new MapperMappingException(newContext, ex); } } }
public Expression MapExpression(IConfigurationProvider configurationProvider, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression) { return(Call(null, MapMethodInfo.MakeGenericMethod(sourceExpression.Type, destExpression.Type), sourceExpression)); }
public Expression MapExpression(IConfigurationProvider configurationProvider, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression) { var destinationType = destExpression.Type; var destinationEnumType = TypeHelper.GetEnumerationType(destinationType); var enumParse = Call(typeof(Enum), "Parse", null, Constant(destinationEnumType), sourceExpression, Constant(true)); var isNullOrEmpty = Call(typeof(string), "IsNullOrEmpty", null, sourceExpression); return(Condition(isNullOrEmpty, Default(destinationType), ToType(enumParse, destinationType))); }
private static MemberAssignment BindAssignableExpression(PropertyMap propertyMap, ExpressionResolutionResult result) { return(Expression.Bind(propertyMap.DestinationProperty.MemberInfo, result.ResolutionExpression)); }
private Expression CreatePropertyMapFunc(PropertyMap propertyMap) { var destMember = MakeMemberAccess(_destination, propertyMap.DestinationProperty); Expression getter; var pi = propertyMap.DestinationProperty as PropertyInfo; if (pi != null && pi.GetGetMethod(true) == null) { getter = Default(propertyMap.DestinationPropertyType); } else { getter = destMember; } Expression destValueExpr; if (propertyMap.UseDestinationValue) { destValueExpr = getter; } else { if (_initialDestination.Type.IsValueType()) { destValueExpr = Default(propertyMap.DestinationPropertyType); } else { destValueExpr = Condition(Equal(_initialDestination, Constant(null)), Default(propertyMap.DestinationPropertyType), getter); } } var valueResolverExpr = BuildValueResolverFunc(propertyMap, getter); var resolvedValue = Variable(valueResolverExpr.Type, "resolvedValue"); var setResolvedValue = Assign(resolvedValue, valueResolverExpr); valueResolverExpr = resolvedValue; var typePair = new TypePair(valueResolverExpr.Type, propertyMap.DestinationPropertyType); valueResolverExpr = propertyMap.Inline ? MapExpression(typePair, valueResolverExpr, propertyMap, destValueExpr) : ContextMap(typePair, valueResolverExpr, _context, destValueExpr); ParameterExpression propertyValue; Expression setPropertyValue; if (valueResolverExpr == resolvedValue) { propertyValue = resolvedValue; setPropertyValue = setResolvedValue; } else { propertyValue = Variable(valueResolverExpr.Type, "propertyValue"); setPropertyValue = Assign(propertyValue, valueResolverExpr); } Expression mapperExpr; if (propertyMap.DestinationProperty is FieldInfo) { mapperExpr = propertyMap.SourceType != propertyMap.DestinationPropertyType ? Assign(destMember, ToType(propertyValue, propertyMap.DestinationPropertyType)) : Assign(getter, propertyValue); } else { var setter = ((PropertyInfo)propertyMap.DestinationProperty).GetSetMethod(true); if (setter == null) { mapperExpr = propertyValue; } else { mapperExpr = Assign(destMember, ToType(propertyValue, propertyMap.DestinationPropertyType)); } } if (propertyMap.Condition != null) { mapperExpr = IfThen( propertyMap.Condition.ConvertReplaceParameters( _source, _destination, ToType(propertyValue, propertyMap.Condition.Parameters[2].Type), ToType(getter, propertyMap.Condition.Parameters[2].Type), _context ), mapperExpr ); } mapperExpr = Block(new[] { setResolvedValue, setPropertyValue, mapperExpr }.Distinct()); if (propertyMap.PreCondition != null) { mapperExpr = IfThen( propertyMap.PreCondition.ConvertReplaceParameters(_source, _context), mapperExpr ); } return(Block(new[] { resolvedValue, propertyValue }.Distinct(), mapperExpr)); }
public bool IsMatch(PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionResolutionResult result) => propertyTypeMap?.CustomMapExpression != null;
public bool IsMatch(PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionResolutionResult result) { return(propertyMap.DestinationPropertyType.IsAssignableFrom(result.Type)); }
public Expression MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression) => Expression.Multiply(Expression.Convert(sourceExpression, typeof(int)), Expression.Constant(1000));
public MemberAssignment Build(IMappingEngine mappingEngine, PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionRequest request, ExpressionResolutionResult result, ConcurrentDictionary <ExpressionRequest, int> typePairCount) { return(BindAssignableExpression(propertyMap, result)); }
public static Expression MapKeyPairValueExpr(IConfigurationProvider configurationProvider, ProfileMap profileMap, PropertyMap propertyMap, Type sourceType, Type destType, Expression contextParam, out ParameterExpression itemParam) { var sourceElementTypes = ElementTypeHelper.GetElementTypes(sourceType, ElementTypeFlags.BreakKeyValuePair); var destElementTypes = ElementTypeHelper.GetElementTypes(destType, ElementTypeFlags.BreakKeyValuePair); var typePairKey = new TypePair(sourceElementTypes[0], destElementTypes[0]); var typePairValue = new TypePair(sourceElementTypes[1], destElementTypes[1]); var sourceElementType = typeof(KeyValuePair <,>).MakeGenericType(sourceElementTypes); itemParam = Parameter(sourceElementType, "item"); var destElementType = typeof(KeyValuePair <,>).MakeGenericType(destElementTypes); var keyExpr = TypeMapPlanBuilder.MapExpression(configurationProvider, profileMap, typePairKey, Property(itemParam, "Key"), contextParam, propertyMap); var valueExpr = TypeMapPlanBuilder.MapExpression(configurationProvider, profileMap, typePairValue, Property(itemParam, "Value"), contextParam, propertyMap); var keyPair = New(destElementType.GetConstructors().First(), keyExpr, valueExpr); return(keyPair); }
private static MemberAssignment BindCustomProjectionExpression(PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionResolutionResult result) => Expression.Bind(propertyMap.DestinationMember, propertyTypeMap.CustomMapExpression.ReplaceParameters(result.ResolutionExpression));
private PushButton CreateButton(string name, string text) { PushButton button = new PushButton(); button.Focusable = true; button.Size2D = new Size2D(400, 80); button.Focusable = true; button.Name = name; // Create the label which will show when _pushbutton focused. PropertyMap _focusText = CreateTextVisual(text, Color.Black); // Create the label which will show when _pushbutton unfocused. PropertyMap _unfocusText = CreateTextVisual(text, Color.White); button.Label = _unfocusText; // Create normal background visual. PropertyMap normalMap = CreateImageVisual(normalImagePath); // Create focused background visual. PropertyMap focusMap = CreateImageVisual(focusImagePath); // Create pressed background visual. PropertyMap pressMap = CreateImageVisual(pressImagePath); button.SelectedVisual = pressMap; button.UnselectedBackgroundVisual = normalMap; // Chang background Visual and Label when focus gained. button.FocusGained += (obj, e) => { button.UnselectedBackgroundVisual = focusMap; button.Label = _focusText; }; // Chang background Visual and Label when focus lost. button.FocusLost += (obj, e) => { button.UnselectedBackgroundVisual = normalMap; button.Label = _unfocusText; }; // Chang background Visual when pressed. button.KeyEvent += (obj, ee) => { if ("Return" == ee.Key.KeyPressedName) { if (Key.StateType.Down == ee.Key.State) { button.UnselectedBackgroundVisual = pressMap; Tizen.Log.Fatal("NUI", "Press in pushButton sample!!!!!!!!!!!!!!!!"); } else if (Key.StateType.Up == ee.Key.State) { button.UnselectedBackgroundVisual = focusMap; Tizen.Log.Fatal("NUI", "Release in pushButton sample!!!!!!!!!!!!!!!!"); } } return(false); }; return(button); }
public override bool TryRead(ref ReadOnlySpan <byte> remaining, out T?result, PropertyMap propMap = null) { result = null; if (EtfReader.TryReadNullSafe(ref remaining)) { return(true); } if (!_innerConverter.TryRead(ref remaining, out var resultValue, propMap)) { return(false); } result = resultValue; return(true); }
public ExpressionResolutionResult GetExpressionResolutionResult(ExpressionResolutionResult expressionResolutionResult, PropertyMap propertyMap, IValueResolver valueResolver) { var oldParameter = propertyMap.CustomExpression.Parameters.Single(); var newParameter = expressionResolutionResult.ResolutionExpression; var converter = new ParameterConversionVisitor(newParameter, oldParameter); Expression currentChild = converter.Visit(propertyMap.CustomExpression.Body); Type currentChildType = currentChild.Type; return new ExpressionResolutionResult(currentChild, currentChildType); }