Exemple #1
0
        public static bool SerializeDataContract <T>([NotNull] this TextWriter thisValue, T value, DataContractSerializerSettings settings = null, XmlWriterSettings xmlOptions = null)
        {
            XmlWriterSettings opt = xmlOptions ?? XmlWriterHelper.CreateSettings();

            using (XmlWriter writer = XmlWriter.Create(thisValue, opt))
                return(writer.SerializeDataContract(value, settings));
        }
Exemple #2
0
        public static bool SaveAs([NotNull] this DataSet thisValue, [NotNull] string fileName, bool includeSchema = true, XmlWriterSettings options = null)
        {
            if (!IsValid(thisValue, true))
            {
                return(false);
            }

            XmlWriterSettings opt = options ?? XmlWriterHelper.CreateSettings();
            bool result;

            try
            {
                using (XmlWriter writer = XmlWriter.Create(File.OpenWrite(fileName), opt))
                {
                    thisValue.WriteXml(writer, includeSchema ? XmlWriteMode.WriteSchema : XmlWriteMode.IgnoreSchema);
                }

                result = true;
            }
            catch
            {
                result = false;
            }

            return(result);
        }
Exemple #3
0
        public static void SaveFile([NotNull] this XDocument thisValue, [NotNull] string filename, XmlWriterSettings settings)
        {
            XmlWriterSettings options = settings ?? XmlWriterHelper.CreateSettings();

            using (XmlWriter writer = XmlWriter.Create(filename, options))
                thisValue.Save(writer);
        }
Exemple #4
0
        public static string ToXml([NotNull] this DataSet thisValue, bool includeSchema = false, XmlWriterSettings options = null, Encoding encoding = null)
        {
            if (!IsValid(thisValue, true))
            {
                return(null);
            }

            StringBuilder     sb  = new StringBuilder();
            XmlWriterSettings opt = options ?? XmlWriterHelper.CreateSettings(level: ConformanceLevel.Fragment, encoding: encoding);

            using (XmlWriter writer = XmlWriter.Create(sb, opt))
                thisValue.WriteXml(writer, includeSchema ? XmlWriteMode.WriteSchema : XmlWriteMode.IgnoreSchema);

            return(sb.ToString());
        }
        public static string ToXml([NotNull] this DataTable thisValue, bool includeSchema = false, XmlWriterSettings options = null)
        {
            if (!IsValid(thisValue, true))
            {
                return(null);
            }

            StringBuilder     sb  = new StringBuilder();
            XmlWriterSettings opt = options ?? XmlWriterHelper.CreateSettings();

            using (XmlWriter writer = XmlWriter.Create(sb, opt))
                thisValue.WriteXml(writer, includeSchema ? XmlWriteMode.WriteSchema : XmlWriteMode.IgnoreSchema);

            return(sb.ToString());
        }
Exemple #6
0
        public static string ReadToEnd([NotNull] this MessageBuffer thisValue, XmlWriterSettings settings = null)
        {
            using (Message message = thisValue.CreateMessage())
            {
                if (message.IsEmpty)
                {
                    return(string.Empty);
                }

                StringBuilder sb = new StringBuilder();

                using (XmlWriter writer = XmlWriter.Create(sb, settings ?? XmlWriterHelper.CreateSettings()))
                {
                    message.WriteMessage(writer);
                }

                return(sb.ToString());
            }
        }
Exemple #7
0
 public static void SaveFile([NotNull] this XDocument thisValue, [NotNull] string filename, Encoding encoding)
 {
     SaveFile(thisValue, filename, XmlWriterHelper.CreateSettings(encoding: encoding));
 }