NMF.Serialization.Xmi.XmiSerializer.WriteElementProperties C# (CSharp) 메소드

WriteElementProperties() 보호된 메소드

protected WriteElementProperties ( System writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context ) : void
writer System
obj object
info ITypeSerializationInfo
context XmlSerializationContext
리턴 void
        protected override void WriteElementProperties(System.Xml.XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
        {
            foreach (XmlPropertySerializationInfo pi in info.ElementProperties)
            {
                var value = pi.GetValue(obj, context);
                if (pi.ShouldSerializeValue(obj, value))
                {
                    if (pi.PropertyType.IsCollection)
                    {
                        var collectionType = pi.PropertyType.CollectionItemType.Type;
                        foreach (object item in value as IEnumerable)
                        {
                            writer.WriteStartElement(pi.NamespacePrefix, pi.ElementName, pi.Namespace);
                            var itemType = item.GetType();
                            var itemInfo = GetSerializationInfo(itemType, true);
                            if (itemType != collectionType)
                            {
                                WriteTypeQualifier(writer, itemInfo);
                            }
                            if (itemInfo.IsStringConvertible)
                            {
                                writer.WriteString(itemInfo.ConvertToString(item));
                            }
                            else
                            {
                                Serialize(item, writer, pi, false, pi.IdentificationMode, context);
                            }
                            writer.WriteEndElement();
                        }
                    }
                    else
                    {
                        writer.WriteStartElement(pi.NamespacePrefix, pi.ElementName, pi.Namespace);
                        if (value != null)
                        {
                            var type = value.GetType();
                            if (type != pi.PropertyType.Type.GetImplementationType())
                            {
                                WriteTypeQualifier(writer, GetSerializationInfo(type, true));
                            }
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                        Serialize(value, writer, pi, false, pi.IdentificationMode, context);
                        writer.WriteEndElement();
                    }
                }
            }
        }