diff --git a/src/XmlSerializerExtensions.cs b/src/XmlSerializerExtensions.cs index d17acc4e..452e8ae3 100644 --- a/src/XmlSerializerExtensions.cs +++ b/src/XmlSerializerExtensions.cs @@ -12,6 +12,17 @@ public static class XmlSerializerExtensions public static byte[] SerializeToXml(this T @object) { var serializer = new XmlSerializer(typeof(T)); + return SerializeToXml(@object, serializer); + } + + public static byte[] SerializeToXml(object @object) + { + var serializer = new XmlSerializer(@object.GetType()); + return SerializeToXml(@object, serializer); + } + + private static byte[] SerializeToXml(T @object, XmlSerializer serializer) + { using (var ms = new MemoryStream()) { using (var sw = new StreamWriter(ms, Encoding.UTF8)) @@ -24,7 +35,8 @@ public static byte[] SerializeToXml(this T @object) namespaces.Add("", ns); } - serializer.Serialize(sw, @object, namespaces ?? new XmlSerializerNamespaces(new[] {new XmlQualifiedName(string.Empty)})); + serializer.Serialize(sw, @object, + namespaces ?? new XmlSerializerNamespaces(new[] {new XmlQualifiedName(string.Empty)})); } return ms.ToArray();