public static string ToXml(this IXmlConverter converter, Type valueType, object value, XmlMember member = null, XmlContract contract = null, XmlSerializerSettings settings = null)
        {
            var builder = new StringBuilder();
            var context = CreateContext(valueType, member, contract, settings);

            using (var output = new StringWriter(builder))
                using (var writer = XmlWriter.Create(output, context.Settings.GetWriterSettings()))
                {
                    writer.WriteStartElement("xml");

                    var isAttribute = context.Member.MappingType == XmlMappingType.Attribute;

                    if (isAttribute)
                    {
                        writer.WriteStartAttribute(context.Member.Name);
                    }

                    converter.WriteXml(writer, value, context);

                    if (isAttribute)
                    {
                        writer.WriteEndAttribute();
                    }

                    writer.WriteEndElement();
                }

            return(builder.ToString());
        }