/// <inheritdoc/>
        public string Serialize <T>(T data, Encoding encoding)
        {
            if (data == default)
            {
                return(null);
            }

            var serializer = new XmlSerializer(data.GetType());

            using (var stringWriter = new DynamicEncodingStringWriter(encoding))
            {
                serializer.Serialize(stringWriter, data);
                return(stringWriter.ToString());
            }
        }
Example #2
0
        /// <inheritdoc/>
        public string Serialize <T>(T data, Encoding encoding)
        {
            if (data == default)
            {
                return(null);
            }

            var serializer = new XmlSerializer(typeof(T));

            using (var stringWriter = new DynamicEncodingStringWriter(encoding))
            {
                using (var writer = XmlWriter.Create(stringWriter, WriterSettings))
                {
                    serializer.Serialize(writer, data);
                    return(stringWriter.ToString());
                }
            }
        }