diff --git a/DragonFruit.Common.Data/Extensions/HashExtensions.cs b/DragonFruit.Common.Data/Extensions/HashExtensions.cs deleted file mode 100644 index 3efb84a..0000000 --- a/DragonFruit.Common.Data/Extensions/HashExtensions.cs +++ /dev/null @@ -1,10 +0,0 @@ -// DragonFruit.Common Copyright 2020 DragonFruit Network -// Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details - -namespace DragonFruit.Common.Data.Extensions -{ - public static class HashExtensions - { - public static string ItemHashCode(this object data) => data == null ? "!" : data.GetHashCode().ToString(); - } -} diff --git a/DragonFruit.Common.Data/Serializers/ApiSerializer.cs b/DragonFruit.Common.Data/Serializers/ApiSerializer.cs index a5d6857..107397b 100644 --- a/DragonFruit.Common.Data/Serializers/ApiSerializer.cs +++ b/DragonFruit.Common.Data/Serializers/ApiSerializer.cs @@ -3,6 +3,7 @@ using System.IO; using System.Net.Http; +using System.Net.Http.Headers; using System.Text; #pragma warning disable 618 @@ -37,5 +38,23 @@ public Encoding Encoding public abstract HttpContent Serialize(T input) where T : class; public abstract T Deserialize(Stream input) where T : class; + + /// + /// Converts a serialized in the to the equivalent + /// + /// The stream to convert + protected HttpContent GetHttpContent(Stream stream) + { + stream.Seek(0, SeekOrigin.Begin); + var content = new StreamContent(stream); + + content.Headers.ContentLength = stream.Length; + content.Headers.ContentType = new MediaTypeHeaderValue(ContentType) + { + CharSet = Encoding.HeaderName + }; + + return content; + } } } diff --git a/DragonFruit.Common.Data/Utils/SerializerUtils.cs b/DragonFruit.Common.Data/Utils/SerializerUtils.cs index f24e896..b211c12 100644 --- a/DragonFruit.Common.Data/Utils/SerializerUtils.cs +++ b/DragonFruit.Common.Data/Utils/SerializerUtils.cs @@ -1,6 +1,7 @@ // DragonFruit.Common Copyright 2021 DragonFruit Network // Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details +using System; using System.IO; using System.Net.Http; using System.Net.Http.Headers; @@ -10,6 +11,7 @@ namespace DragonFruit.Common.Data.Utils { public static class SerializerUtils { + [Obsolete("Now available as ApiSerializer.GetHttpContent(stream). This will be removed in the future")] public static HttpContent ProcessStream(ISerializer serializer, Stream stream) { stream.Seek(0, SeekOrigin.Begin);