Example #1
0
        private static XmlObjectMappingItemCollection GetMappingItemCollection(System.Type type)
        {
            XmlObjectMappingItemCollection result = new XmlObjectMappingItemCollection();
            bool onlyMapMarkedProperties          = true;

            XmlRootMappingAttribute rootAttr =
                (XmlRootMappingAttribute)XmlRootMappingAttribute.GetCustomAttribute(type, typeof(XmlRootMappingAttribute), true);

            if (rootAttr != null)
            {
                result.RootName         = rootAttr.RootName;
                onlyMapMarkedProperties = rootAttr.OnlyMapMarkedProperties;
            }
            else
            {
                result.RootName = type.Name;
            }

            MemberInfo[] mis = GetTypeMembers(type);

            foreach (MemberInfo mi in mis)
            {
                if (mi.MemberType == MemberTypes.Field || mi.MemberType == MemberTypes.Property)
                {
                    XmlObjectMappingItemCollection items = CreateMappingItems(mi, onlyMapMarkedProperties);

                    MergeMappingItems(result, items);
                }
            }

            return(result);
        }
Example #2
0
        private static XmlObjectMappingItemCollection GetMappingItemsBySubClass(RelativeAttributes attrs, MemberInfo sourceMI)
        {
            XmlObjectMappingItemCollection items = new XmlObjectMappingItemCollection();

            System.Type subType = attrs.SubClassType != null ? attrs.SubClassType.Type : GetRealType(sourceMI);

            MemberInfo[] mis = GetTypeMembers(subType);

            foreach (XmlObjectSubClassMappingAttribute attr in attrs.SubClassFieldMappings)
            {
                MemberInfo mi = GetMemberInfoByName(attr.SubPropertyName, mis);

                if (mi != null)
                {
                    if (items.Contains(attr.NodeName) == false)
                    {
                        XmlObjectMappingItem item = new XmlObjectMappingItem(attr);

                        item.PropertyName         = sourceMI.Name;
                        item.SubClassPropertyName = attr.SubPropertyName;
                        item.MemberInfo           = mi;

                        if (attrs.SubClassType != null)
                        {
                            item.SubClassTypeDescription = attrs.SubClassType.TypeDescription;
                        }

                        items.Add(item);
                    }
                }
            }

            return(items);
        }
Example #3
0
 private static void MergeMappingItems(XmlObjectMappingItemCollection dest, XmlObjectMappingItemCollection src)
 {
     foreach (XmlObjectMappingItem item in src)
     {
         if (dest.Contains(item.NodeName) == false)
         {
             dest.Add(item);
         }
     }
 }
Example #4
0
        private static XmlObjectMappingItemCollection CreateMappingItems(MemberInfo mi, bool onlyMapMarkedProperties)
        {
            XmlObjectMappingItemCollection result = null;
            bool isDoMapping = false;

            RelativeAttributes attrs = null;

            if (mi.Name != "Item")
            {
                attrs = GetRelativeAttributes(mi);

                if (onlyMapMarkedProperties)
                {
                    isDoMapping = attrs.FieldMapping != null;
                }
                else
                {
                    isDoMapping = true;
                }

                if (isDoMapping && attrs.NoMapping == null)
                {
                    isDoMapping = true;
                }
                else
                {
                    isDoMapping = false;
                }
            }

            if (isDoMapping == true)
            {
                if (attrs != null)
                {
                    if (attrs.SubClassFieldMappings.Count > 0)
                    {
                        result = GetMappingItemsBySubClass(attrs, mi);
                    }
                    else
                    {
                        result = GetMappingItems(attrs, mi);
                    }
                }
            }
            else
            {
                result = new XmlObjectMappingItemCollection();
            }

            return(result);
        }
Example #5
0
        private static XmlObjectMappingItemCollection GetMappingItems(RelativeAttributes attrs, MemberInfo mi)
        {
            XmlObjectMappingItemCollection items = new XmlObjectMappingItemCollection();

            XmlObjectMappingItem item = new XmlObjectMappingItem(attrs.FieldMapping);

            item.PropertyName = mi.Name;
            if (string.IsNullOrEmpty(item.NodeName))
            {
                item.NodeName = mi.Name;
            }

            item.MemberInfo = mi;

            items.Add(item);

            return(items);
        }