コード例 #1
0
ファイル: XmlSerialization.cs プロジェクト: bixiu/BlueMine
        }     // End Class AccessorCache<T>


        public static void SerializeToXml <T>(T ThisTypeInstance, System.IO.TextWriter tw)
        {
            // System.Xml.Serialization.XmlSerializerNamespaces ns =
            //  new System.Xml.Serialization.XmlSerializerNamespaces();

            //Add an empty namespace and empty value
            // ns.Add("", "");

            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
            // serializer.Serialize(tw, ThisTypeInstance, ns);
            // serializer.Serialize(tw, ThisTypeInstance);

            System.Xml.Serialization.XmlSerializerNamespaces xns =
                AccessorCache <T> .GetNamespaces(ThisTypeInstance);

            using (NoXsdXsiXmlWriter noXsd = new NoXsdXsiXmlWriter(tw))
            {
                serializer.Serialize(noXsd, ThisTypeInstance, xns);
            } // End Using noXsd

            //using (var ix = new NoNamespaceXmlWriter(tw))
            //{
            //    serializer.Serialize(ix, ThisTypeInstance);
            //}

            serializer = null;
        } // End Sub SerializeToXml