コード例 #1
0
 public void ctor_StringBuilder_IFormatProvider_Encoding()
 {
     using (var obj = new EncodedStringWriter(new StringBuilder(), CultureInfo.InvariantCulture, Encoding.UTF8))
     {
         Assert.NotNull(obj);
     }
 }
コード例 #2
0
 public void ctor_StringBuilder_Encoding()
 {
     using (var obj = new EncodedStringWriter(new StringBuilder(), Encoding.UTF8))
     {
         Assert.NotNull(obj);
     }
 }
コード例 #3
0
 public void ctor_Encoding()
 {
     using (var obj = new EncodedStringWriter(Encoding.UTF8))
     {
         Assert.NotNull(obj);
     }
 }
コード例 #4
0
        public void prop_Encoding_get()
        {
            var expected = Encoding.UTF8;
            Encoding actual;

            using (var obj = new EncodedStringWriter(new StringBuilder(), CultureInfo.InvariantCulture, expected))
            {
                actual = obj.Encoding;
            }

            Assert.Equal(expected, actual);
        }
コード例 #5
0
        public void prop_Encoding_get()
        {
            var      expected = Encoding.UTF8;
            Encoding actual;

            using (var obj = new EncodedStringWriter(new StringBuilder(), CultureInfo.InvariantCulture, expected))
            {
                actual = obj.Encoding;
            }

            Assert.Equal(expected, actual);
        }
コード例 #6
0
        public static IXPathNavigable XmlSerialize(this object value)
#endif
        {
            if (null == value)
            {
                throw new ArgumentNullException("value");
            }

            var result = new XmlDocument();

            var buffer = new StringBuilder();

            var exception = value as Exception;
#if NET20
            if (ObjectExtensionMethods.IsNotNull(exception))
#else
            if (exception.IsNotNull())
#endif
            {
                using (var stream = new MemoryStream())
                {
                    new SoapFormatter().Serialize(stream, value);
                    stream.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(stream))
                    {
                        buffer.Append(reader.ReadToEnd());
                    }
                }
            }
            else
            {
                using (TextWriter writer = new EncodedStringWriter(buffer, CultureInfo.InvariantCulture, Encoding.UTF8))
                {
                    XmlSerializerNamespaces namespaces;
                    var obj = value as IXmlSerializerNamespaces;
                    if (null == obj)
                    {
                        namespaces = new XmlSerializerNamespaces();
                        namespaces.Add(string.Empty, string.Empty);
                    }
                    else
                    {
                        namespaces = obj.XmlNamespaceDeclarations;
                    }

                    new XmlSerializer(value.GetType()).Serialize(writer, value, namespaces);
                }
            }

            result.LoadXml(buffer.ToString());

            return result;
        }