Exemplo n.º 1
0
        private void SerializableBinaryToNode(XElement parent, XmlObjectMappingItem item, object graph, XmlSerializeContext context)
        {
            //此处对没有标记为序列化的需要做一个异常处理,还是?
            XElement xElement = context.RootElement.AddChildElement("object");

            xElement.SetAttributeValue("id", context.CurrentID++);

            if (this.OutputShortType)
            {
                xElement.SetAttributeValue("shortType", graph.GetType().Name);
            }

            xElement.SetAttributeValue("oti", context.GetTypeID(graph.GetType()));

            XElement itemNode = xElement.AddChildElement("value");

            byte[] buffer = null;
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, graph);
                buffer = ms.GetBuffer();
            }
            string imageBase64String = Convert.ToBase64String(buffer);

            itemNode.Add(imageBase64String);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private void SerializableBinaryToNode(XElement parent, XmlObjectMappingItem item, object graph, XmlSerializeContext context)
        {
            //此处对没有标记为序列化的需要做一个异常处理,还是?
            XElement xElement = context.RootElement.AddChildElement("object");
            xElement.SetAttributeValue("id", context.CurrentID++);

            if (this.OutputShortType)
                xElement.SetAttributeValue("shortType", graph.GetType().Name);

            xElement.SetAttributeValue("oti", context.GetTypeID(graph.GetType()));

            XElement itemNode = xElement.AddChildElement("value");

            byte[] buffer = null;
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, graph);
                buffer = ms.GetBuffer();
            }
            string imageBase64String = Convert.ToBase64String(buffer);

            itemNode.Add(imageBase64String);
        }