Exemplo n.º 1
0
        private bool CanReadXml <T>(XmlReader reader)
            where T : IXmlSerializable, new()
        {
            XmlRootAttribute attr;

            if (Utils.TryGetCustomAttribute <XmlRootAttribute, T>(out attr, false))
            {
                if (attr.ElementName == reader.LocalName)
                {
                    return(true);
                }
            }
            else
            {
                if (typeof(ITypedXmlSerializable).IsAssignableFrom(typeof(T)))
                {
                    T t = new T();
                    ITypedXmlSerializable typed = (ITypedXmlSerializable)t;
                    if (typed.XmlElementName == reader.LocalName)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public static string WriteXmlFragment(ITypedXmlSerializable serializable)
        {
            StringBuilder sb = new StringBuilder();

            using (TextWriter writer = new StringWriter(sb, CultureInfo.InvariantCulture))
            {
                using (XmlWriter xmlWriter = XmlWriter.Create(writer, XmlUtils.CreateFragmentWriterSettings()))
                {
                    xmlWriter.WriteStartElement(serializable.XmlElementName, serializable.XmlSchemaNamespace);
                    serializable.WriteXml(xmlWriter);
                    xmlWriter.WriteEndElement();
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 3
0
 public static void ReadElement(XmlReader reader, ITypedXmlSerializable instance)
 {
     XmlUtils.ReadElement(reader, instance.XmlElementName, instance);
 }
Exemplo n.º 4
0
 public static void WriteElement(XmlWriter writer, ITypedXmlSerializable instance)
 {
     XmlUtils.WriteElement(writer, instance.XmlElementName, instance);
 }