public void SimpleTest() { // we set as root a typePair different from (object,object) var falseRoot = new TypeMapping(null, typeof(object), typeof(string)); var tree = new ConfigInheritanceTree(falseRoot); //we add the real root (object,object) tree.Add(new TypeMapping(null, typeof(object), typeof(object))); tree.Add(new TypeMapping(null, typeof(Dictionary <string, string>), typeof(Dictionary <string, string>))); tree.Add(new TypeMapping(null, typeof(ObservableCollection <string>), typeof(IList <string>))); tree.Add(new TypeMapping(null, typeof(IList <string>), typeof(IList <string>))); tree.Add(new TypeMapping(null, typeof(ICollection <string>), typeof(ICollection <string>))); tree.Add(new TypeMapping(null, typeof(Collection <string>), typeof(Collection <string>))); tree.Add(new TypeMapping(null, typeof(List <string>), typeof(List <string>))); tree.Add(new TypeMapping(null, typeof(IEnumerable <string>), typeof(IEnumerable <string>))); tree.Add(new TypeMapping(null, typeof(IEnumerable <char>), typeof(IEnumerable <char>))); tree.Add(new TypeMapping(null, typeof(IEnumerable <IEnumerable <char> >), typeof(IEnumerable <IEnumerable <char> >))); tree.Add(new TypeMapping(null, typeof(object), typeof(string))); tree.Add(new TypeMapping(null, typeof(string), typeof(string))); //check root is been updated Assert.IsTrue(tree.Root.Item.Source.EntryType == typeof(object)); Assert.IsTrue(tree.Root.Item.Target.EntryType == typeof(object)); //no duplicates allowed var dup1 = new TypeMapping(null, typeof(object), typeof(object)); var dup2 = new TypeMapping(null, typeof(IEnumerable <IEnumerable <char> >), typeof(IEnumerable <IEnumerable <char> >)); var dup3 = new TypeMapping(null, typeof(object), typeof(string)); tree.Add(dup1); tree.Add(dup2); tree.Add(dup3); }
public Configuration(Action <Configuration> config = null) { var rootMapping = new TypeMapping(this, typeof(object), typeof(object)) { //Must not use INHERIT as a value for root-mapping options ReferenceBehavior = ReferenceBehaviors.CREATE_NEW_INSTANCE, CollectionBehavior = CollectionBehaviors.RESET }; TypeMappingTree = new ConfigInheritanceTree(rootMapping); ExpCache = new GeneratedExpressionCache(); //Order is important: the first MapperExpressionBuilder able to handle a mapping is used. //Make sure to use a collection which preserve insertion order! this.Mappers = new OrderedTypeSet <IMappingExpressionBuilder>() { //new MemberMapper( this ), //new AbstractMappingExpressionBuilder(this), new StringToEnumMapper(this), new EnumMapper(this), new BuiltInTypeMapper(this), new NullableMapper(this), new StructMapper(this), new ConvertMapper(this), new ArrayMapper(this), new DictionaryMapper(this), new ReadOnlyCollectionMapper(this), new StackMapper(this), new QueueMapper(this), new LinkedListMapper(this), new CollectionMapper(this), new ReferenceMapper(this), new ReferenceToStructMapper(this), }; this.Conventions = new TypeSet <IMappingConvention>(cfg => { cfg.GetOrAdd <DefaultConvention>(conv => { conv.SourceMemberProvider.IgnoreProperties = false; conv.SourceMemberProvider.IgnoreFields = true; conv.SourceMemberProvider.IgnoreNonPublicMembers = true; conv.SourceMemberProvider.IgnoreMethods = true; conv.TargetMemberProvider.IgnoreProperties = false; conv.TargetMemberProvider.IgnoreFields = true; conv.TargetMemberProvider.IgnoreNonPublicMembers = true; conv.TargetMemberProvider.IgnoreMethods = true; conv.MatchingRules .GetOrAdd <ExactNameMatching>(rule => rule.IgnoreCase = true) .GetOrAdd <PrefixMatching>(rule => rule.IgnoreCase = true) .GetOrAdd <SuffixMatching>(rule => rule.IgnoreCase = true); }); }); this.ConventionResolver = new DefaultConventionResolver(); BuiltInConverters.AddStringToDateTime(this); //BuiltInConverters.AddPrimitiveTypeToItself( this ); //BuiltInConverters.AddExplicitNumericConverters( this ); //BuiltInConverters.AddImplicitNumericConverters( this ); //BuiltInConverters.AddPrimitiveTypeToStringConverters( this ); //BuiltInConverters.AddStringToPrimitiveTypeConverters( this ); config?.Invoke(this); }