/// <summary>We need to distribute all "common" mappings to every applicable "type-based" mappings</summary> /// <param name="mapping"></param> /// <param name="beanProperty"></param> private void AddDuplicates(Mapping mapping, BeanProperty beanProperty) { IList <RelationshipMap.Key> allTypeBased = this.map.GetAllTypeBased(mapping.First()); foreach (RelationshipMap.Key key in allTypeBased) { object @object = this.map.Get(key); if (@object is Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter) { Mapping rest = mapping.Rest(); Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter innerRelationshipSorter = (Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter )@object; if (rest.IsCompound()) { innerRelationshipSorter.properties[beanProperty.Name] = beanProperty; // TM - Redmine 10965 - this "if" check fixes bug, might not be sufficient in the long run if (innerRelationshipSorter.map.GetAllTypeBased(rest.First()).IsEmpty()) { innerRelationshipSorter.Add(rest, beanProperty); } else { innerRelationshipSorter.AddDuplicates(rest, beanProperty); } } else { // we are at the "bottom" of the chain - now we can add the "duplicate" property to its correct location innerRelationshipSorter.Add(rest, beanProperty); } } } }
internal static Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter Create(string propertyName, object tealBean) { Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter holder = new Ca.Infoway.Messagebuilder.Marshalling.RelationshipSorter (propertyName, tealBean == null ? null : tealBean.GetType(), tealBean); IDictionary <string, BeanProperty> properties = BeanProperty.GetProperties(tealBean); foreach (BeanProperty property in properties.Values) { IList <Mapping> mappings = Mapping.From(property); foreach (Mapping mapping in mappings) { holder.Add(mapping, property); } } foreach (BeanProperty property in properties.Values) { IList <Mapping> mappings = Mapping.From(property); foreach (Mapping mapping in mappings) { // if this is an inlined "common" mapping, we need to add it to appropriate "type-based" mappings if (mapping.IsCompound() && !mapping.HasPartTypeMappings()) { holder.AddDuplicates(mapping, property); } } } return(holder); }