diff --git a/src/Modules/ModelMapper/Readme.md b/src/Modules/ModelMapper/Readme.md index 25ac8e95c..0f70990cd 100644 --- a/src/Modules/ModelMapper/Readme.md +++ b/src/Modules/ModelMapper/Readme.md @@ -164,7 +164,7 @@ DashboardView | ListView | DetailView ---------|----------|--------- ![image](https://user-images.githubusercontent.com/159464/61752712-73808880-adb5-11e9-897e-081e8864882f.png)|![image](https://user-images.githubusercontent.com/159464/61752825-ec7fe000-adb5-11e9-8217-2e125f992319.png)|![image](https://user-images.githubusercontent.com/159464/61752720-7f6c4a80-adb5-11e9-832e-931a23b8a159.png) -##### How to customize a map +##### How to customize a map You can customize the map the following ways: 1. On declaration using the ModelMapperConfiguration properties. ```cs @@ -192,7 +192,7 @@ You can customize the map the following ways: })); ``` Several real world examples are available at [Predefined](https://github.com/eXpandFramework/DevExpress.XAF/tree/master/src/Modules/ModelMapper/Services/Predefined) namespace. -##### How to bind a map +##### How to bind a map All predefined maps are bound to the runtime instance automatically. The module when any view controls are created will search its model for IModelModelMap properties and use them to configure the related instances. It is possible to customize the process as in next snippet: diff --git a/src/Tests/ModelMapper/TypeMappingServiceTests/MapTests.cs b/src/Tests/ModelMapper/TypeMappingServiceTests/MapTests.cs index 2957502eb..33e90dd2a 100644 --- a/src/Tests/ModelMapper/TypeMappingServiceTests/MapTests.cs +++ b/src/Tests/ModelMapper/TypeMappingServiceTests/MapTests.cs @@ -404,6 +404,26 @@ public class MapTests:ModelMapperBaseTest{ modelNames.ShouldContain(types.Last().Name); } + + [Test] + public void Customize_TypeMapping(){ + InitializeMapperService($"{nameof(Customize_TypeMapping)}",Platform.Win); + TypeMappingService.PropertyMappingRules.Add(("RemoveTreeListMap", _ => { + if (_.declaringType == PredefinedMap.TreeList.TypeToMap()){ + _.propertyInfos.Clear(); + } + })); + + var modelInterfaces = new[]{PredefinedMap.GridView,PredefinedMap.TreeList}.MapToModel().ModelInterfaces().Replay(); + modelInterfaces.Connect(); + + var types = modelInterfaces.ToEnumerable().ToArray(); + types.Length.ShouldBe(2); + types.Last().GetProperties() + .FirstOrDefault(info => !TypeMappingService.ReservedPropertyNames.Contains(info.Name)&&info.Name!=TypeMappingService.ModelMappersNodeName) + .ShouldBeNull(); + + } }