diff --git a/Hyperion.sln b/Hyperion.sln index 9cfc24f0..d26910ab 100644 --- a/Hyperion.sln +++ b/Hyperion.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27004.2005 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31112.23 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperion", "src\Hyperion\Hyperion.csproj", "{7AF8D2B6-9F1F-4A1C-8673-48E533108385}" EndProject @@ -19,7 +19,11 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Hyperion.Tests.FSharpData", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperion.Benchmarks", "src\Hyperion.Benchmarks\Hyperion.Benchmarks.csproj", "{CAE2DB69-0BE7-4B11-96DB-D5B61D35607F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hyperion.Tests", "src\Hyperion.Tests\Hyperion.Tests.csproj", "{EA096BA2-3B4C-4878-B9AD-5A88D164EBF0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperion.Tests", "src\Hyperion.Tests\Hyperion.Tests.csproj", "{EA096BA2-3B4C-4878-B9AD-5A88D164EBF0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hyperion.Akka.Integration.Tests", "src\Hyperion.Akka.Integration.Tests\Hyperion.Akka.Integration.Tests.csproj", "{3DA946AF-0CCD-49A9-AA77-67FA515A83EE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hyperion.API.Tests", "src\Hyperion.API.Tests\Hyperion.API.Tests.csproj", "{767FBBD2-869C-4AAD-ABF4-F23EC0D381AA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -43,6 +47,14 @@ Global {EA096BA2-3B4C-4878-B9AD-5A88D164EBF0}.Debug|Any CPU.Build.0 = Debug|Any CPU {EA096BA2-3B4C-4878-B9AD-5A88D164EBF0}.Release|Any CPU.ActiveCfg = Release|Any CPU {EA096BA2-3B4C-4878-B9AD-5A88D164EBF0}.Release|Any CPU.Build.0 = Release|Any CPU + {3DA946AF-0CCD-49A9-AA77-67FA515A83EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3DA946AF-0CCD-49A9-AA77-67FA515A83EE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3DA946AF-0CCD-49A9-AA77-67FA515A83EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3DA946AF-0CCD-49A9-AA77-67FA515A83EE}.Release|Any CPU.Build.0 = Release|Any CPU + {767FBBD2-869C-4AAD-ABF4-F23EC0D381AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {767FBBD2-869C-4AAD-ABF4-F23EC0D381AA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {767FBBD2-869C-4AAD-ABF4-F23EC0D381AA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {767FBBD2-869C-4AAD-ABF4-F23EC0D381AA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 568754ea..8869ac98 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,22 +1,2 @@ -### 0.10.0 April 13 2021 #### -* [Add a generic cross platform serialization support](https://github.com/akkadotnet/Hyperion/pull/208) - -# Cross platform serialization - -You can now address any cross platform package serialization differences by providing a list of package name transformation lambda function into the `SerializerOptions` constructor. The package name will be passed into the lambda function before it is deserialized, and the result of the string transformation is used for deserialization instead of the original package name. - -This short example shows how to address the change from `System.Drawing` in .NET Framework to `System.Drawing.Primitives` in .NET Core: - -``` -Serializer serializer; -#if NETFX -serializer = new Serializer(new SerializerOptions( - packageNameOverrides: new List> { - str => str.Contains("System.Drawing.Primitives") ? str.Replace(".Primitives", "") : str - })); -#elif NETCOREAPP -serializer = new Serializer(); -#endif -``` - -Note that only one package name transformation is allowed, any transform lambda function after the first applied transformation is ignored. \ No newline at end of file +### 0.10.1 April 20 2021 #### +* [Fix SerializerOptions constructor backward compatibility issue with Akka.NET](https://github.com/akkadotnet/Hyperion/pull/214) diff --git a/src/Hyperion.API.Tests/CoreAPISpec.cs b/src/Hyperion.API.Tests/CoreAPISpec.cs new file mode 100644 index 00000000..fa7cb2e8 --- /dev/null +++ b/src/Hyperion.API.Tests/CoreAPISpec.cs @@ -0,0 +1,40 @@ +using System; +using System.Linq; +using System.Runtime.CompilerServices; +using ApprovalTests; +using ApprovalTests.Reporters; +using PublicApiGenerator; +using Xunit; + +namespace Hyperion.API.Tests +{ +#if(DEBUG) + [UseReporter(typeof(DiffReporter), typeof(AllFailingTestsClipboardReporter))] +#else + [UseReporter(typeof(DiffReporter))] +#endif + public class CoreApiSpec + { + [Fact] + [MethodImpl(MethodImplOptions.NoInlining)] + public void ApproveApi() + { + var publicApi = Filter(typeof(Serializer).Assembly.GeneratePublicApi()); + Approvals.Verify(publicApi); + } + + static string Filter(string text) + { + return string.Join(Environment.NewLine, text.Split(new[] + { + Environment.NewLine + }, StringSplitOptions.RemoveEmptyEntries) + .Where(l => + !l.StartsWith("[assembly: ReleaseDateAttribute(") + && !l.StartsWith("[assembly: System.Security") + && !l.StartsWith("[assembly: System.Runtime.Versioning.TargetFramework(")) + .Where(l => !string.IsNullOrWhiteSpace(l)) + ); + } + } +} diff --git a/src/Hyperion.API.Tests/CoreApiSpec.ApproveApi.approved.txt b/src/Hyperion.API.Tests/CoreApiSpec.ApproveApi.approved.txt new file mode 100644 index 00000000..cf895557 --- /dev/null +++ b/src/Hyperion.API.Tests/CoreApiSpec.ApproveApi.approved.txt @@ -0,0 +1,693 @@ +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Hyperion.Tests")] +[assembly: System.Runtime.InteropServices.ComVisible(false)] +[assembly: System.Runtime.InteropServices.Guid("7af8d2b6-9f1f-4a1c-8673-48e533108385")] +namespace Hyperion.Compilation +{ + public interface ICompiler + { + int Call(System.Reflection.MethodInfo method, int target, params int[] arguments); + int CastOrUnbox(int value, System.Type type); + TDel Compile(); + int Constant(object value); + int Convert(int value, System.Type type); + int Convert(int value); + void Emit(int value); + void EmitCall(System.Reflection.MethodInfo method, int target, params int[] arguments); + void EmitStaticCall(System.Reflection.MethodInfo method, params int[] arguments); + int GetVariable(string name); + int NewObject(System.Type type); + int Parameter(string name); + int ReadField(System.Reflection.FieldInfo field, int target); + int StaticCall(System.Reflection.MethodInfo method, params int[] arguments); + int Variable(string name, System.Type type); + int Variable(string name); + int WriteField(System.Reflection.FieldInfo field, int typedTarget, int target, int value); + int WriteVar(int variable, int value); + } +} +namespace Hyperion +{ + public class DeserializerSession + { + public const int MinBufferSize = 9; + public readonly Hyperion.Serializer Serializer; + public DeserializerSession([Hyperion.Internal.NotNull] Hyperion.Serializer serializer) { } + public byte[] GetBuffer(int length) { } + public object GetDeserializedObject(int id) { } + public System.Type GetTypeFromTypeId(int typeId) { } + public Hyperion.TypeVersionInfo GetVersionInfo([Hyperion.Internal.NotNull] System.Type type) { } + public void TrackDeserializedObject([Hyperion.Internal.NotNull] object obj) { } + public void TrackDeserializedType([Hyperion.Internal.NotNull] System.Type type) { } + public void TrackDeserializedTypeWithVersion([Hyperion.Internal.NotNull] System.Type type, [Hyperion.Internal.NotNull] Hyperion.TypeVersionInfo versionInfo) { } + } + public delegate object FieldInfoReader(object obj); + public delegate void FieldInfoWriter(object obj, object value); + public delegate void FieldReader(System.IO.Stream stream, object obj, Hyperion.DeserializerSession session); + public delegate void FieldsWriter(System.IO.Stream stream, object obj, Hyperion.SerializerSession session); + public interface ICodeGenerator + { + void BuildSerializer(Hyperion.Serializer serializer, Hyperion.ValueSerializers.ObjectSerializer objectSerializer); + } + [System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.All, AllowMultiple=false, Inherited=true)] + public sealed class IgnoreAttribute : System.Attribute + { + public IgnoreAttribute() { } + } + public static class NoAllocBitConverter + { + public static void GetBytes(char value, byte[] bytes) { } + public static void GetBytes(System.DateTime dateTime, byte[] bytes) { } + public static void GetBytes(System.DateTimeOffset dateTime, byte[] bytes) { } + public static void GetBytes(double value, byte[] bytes) { } + public static void GetBytes(short value, byte[] bytes) { } + public static void GetBytes(int value, byte[] bytes) { } + public static void GetBytes(long value, byte[] bytes) { } + public static void GetBytes(float value, byte[] bytes) { } + public static void GetBytes(ushort value, byte[] bytes) { } + public static void GetBytes(uint value, byte[] bytes) { } + public static void GetBytes(ulong value, byte[] bytes) { } + } + public delegate object ObjectReader(System.IO.Stream stream, Hyperion.DeserializerSession session); + public delegate void ObjectWriter(System.IO.Stream stream, object obj, Hyperion.SerializerSession session); + public class Serializer + { + public readonly Hyperion.ICodeGenerator CodeGenerator; + public readonly Hyperion.SerializerOptions Options; + public Serializer() { } + public Serializer([Hyperion.Internal.NotNull] Hyperion.SerializerOptions options) { } + public object Deserialize([Hyperion.Internal.NotNull] System.IO.Stream stream) { } + public object Deserialize([Hyperion.Internal.NotNull] System.IO.Stream stream, Hyperion.DeserializerSession session) { } + public T Deserialize([Hyperion.Internal.NotNull] System.IO.Stream stream) { } + public T Deserialize([Hyperion.Internal.NotNull] System.IO.Stream stream, Hyperion.DeserializerSession session) { } + public Hyperion.ValueSerializers.ValueSerializer GetDeserializerByManifest([Hyperion.Internal.NotNull] System.IO.Stream stream, [Hyperion.Internal.NotNull] Hyperion.DeserializerSession session) { } + public Hyperion.DeserializerSession GetDeserializerSession() { } + public Hyperion.ValueSerializers.ValueSerializer GetSerializerByType([Hyperion.Internal.NotNull] System.Type type) { } + public Hyperion.SerializerSession GetSerializerSession() { } + public void Serialize(object obj, [Hyperion.Internal.NotNull] System.IO.Stream stream) { } + public void Serialize(object obj, [Hyperion.Internal.NotNull] System.IO.Stream stream, Hyperion.SerializerSession session) { } + } + public class SerializerOptions + { + public static readonly Hyperion.SerializerOptions Default; + [System.Obsolete] + public SerializerOptions(bool versionTolerance = false, bool preserveObjectReferences = false, System.Collections.Generic.IEnumerable surrogates = null, System.Collections.Generic.IEnumerable serializerFactories = null, System.Collections.Generic.IEnumerable knownTypes = null, bool ignoreISerializable = false) { } + public SerializerOptions(bool versionTolerance, bool preserveObjectReferences, System.Collections.Generic.IEnumerable surrogates, System.Collections.Generic.IEnumerable serializerFactories, System.Collections.Generic.IEnumerable knownTypes, bool ignoreISerializable, System.Collections.Generic.IEnumerable> packageNameOverrides) { } + public Hyperion.SerializerOptions WithIgnoreSerializable(bool ignoreISerializable) { } + public Hyperion.SerializerOptions WithKnownTypes(System.Collections.Generic.IEnumerable knownTypes) { } + public Hyperion.SerializerOptions WithPackageNameOverrides(System.Collections.Generic.IEnumerable> packageNameOverrides) { } + public Hyperion.SerializerOptions WithPreserveObjectReferences(bool preserveObjectReferences) { } + public Hyperion.SerializerOptions WithSerializerFactory(System.Collections.Generic.IEnumerable serializerFactories) { } + public Hyperion.SerializerOptions WithSurrogates(System.Collections.Generic.IEnumerable surrogates) { } + public Hyperion.SerializerOptions WithVersionTolerance(bool versionTolerance) { } + } + public class SerializerSession + { + public const int MinBufferSize = 9; + public readonly Hyperion.Serializer Serializer; + public SerializerSession(Hyperion.Serializer serializer) { } + public byte[] GetBuffer(int length) { } + public bool ShouldWriteTypeManifest(System.Type type, out ushort index) { } + public void TrackSerializedObject(object obj) { } + public void TrackSerializedType(System.Type type) { } + public bool TryGetObjectId(object obj, out int objectId) { } + public bool TryGetValue(System.Type key, out ushort value) { } + } + public class Surrogate + { + public Surrogate() { } + public System.Type From { get; set; } + public System.Func FromSurrogate { get; set; } + public System.Type To { get; set; } + public System.Func ToSurrogate { get; set; } + public bool IsSurrogateFor(System.Type type) { } + public static Hyperion.Surrogate Create(System.Func toSurrogate, System.Func fromSurrogate) { } + } + public class Surrogate : Hyperion.Surrogate + { + public Surrogate(System.Func toSurrogate, System.Func fromSurrogate) { } + } + public class TypeVersionInfo + { + public TypeVersionInfo() { } + } + public delegate object TypedArray(object obj); +} +namespace Hyperion.Internal +{ + [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class AspChildControlTypeAttribute : System.Attribute + { + public AspChildControlTypeAttribute([Hyperion.Internal.NotNull] string tagName, [Hyperion.Internal.NotNull] System.Type controlType) { } + [Hyperion.Internal.NotNull] + public System.Type ControlType { get; } + [Hyperion.Internal.NotNull] + public string TagName { get; } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.All)] + public sealed class AspDataFieldAttribute : System.Attribute + { + public AspDataFieldAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.All)] + public sealed class AspDataFieldsAttribute : System.Attribute + { + public AspDataFieldsAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.All)] + public sealed class AspMethodPropertyAttribute : System.Attribute + { + public AspMethodPropertyAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcActionAttribute : System.Attribute + { + public AspMvcActionAttribute() { } + public AspMvcActionAttribute([Hyperion.Internal.NotNull] string anonymousProperty) { } + [Hyperion.Internal.CanBeNull] + public string AnonymousProperty { get; } + } + [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcActionSelectorAttribute : System.Attribute + { + public AspMvcActionSelectorAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcAreaAttribute : System.Attribute + { + public AspMvcAreaAttribute() { } + public AspMvcAreaAttribute([Hyperion.Internal.NotNull] string anonymousProperty) { } + [Hyperion.Internal.CanBeNull] + public string AnonymousProperty { get; } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class AspMvcAreaMasterLocationFormatAttribute : System.Attribute + { + public AspMvcAreaMasterLocationFormatAttribute([Hyperion.Internal.NotNull] string format) { } + [Hyperion.Internal.NotNull] + public string Format { get; } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class AspMvcAreaPartialViewLocationFormatAttribute : System.Attribute + { + public AspMvcAreaPartialViewLocationFormatAttribute([Hyperion.Internal.NotNull] string format) { } + [Hyperion.Internal.NotNull] + public string Format { get; } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class AspMvcAreaViewLocationFormatAttribute : System.Attribute + { + public AspMvcAreaViewLocationFormatAttribute([Hyperion.Internal.NotNull] string format) { } + [Hyperion.Internal.NotNull] + public string Format { get; } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcControllerAttribute : System.Attribute + { + public AspMvcControllerAttribute() { } + public AspMvcControllerAttribute([Hyperion.Internal.NotNull] string anonymousProperty) { } + [Hyperion.Internal.CanBeNull] + public string AnonymousProperty { get; } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcDisplayTemplateAttribute : System.Attribute + { + public AspMvcDisplayTemplateAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcEditorTemplateAttribute : System.Attribute + { + public AspMvcEditorTemplateAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcMasterAttribute : System.Attribute + { + public AspMvcMasterAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class AspMvcMasterLocationFormatAttribute : System.Attribute + { + public AspMvcMasterLocationFormatAttribute(string format) { } + public string Format { get; } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcModelTypeAttribute : System.Attribute + { + public AspMvcModelTypeAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcPartialViewAttribute : System.Attribute + { + public AspMvcPartialViewAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class AspMvcPartialViewLocationFormatAttribute : System.Attribute + { + public AspMvcPartialViewLocationFormatAttribute([Hyperion.Internal.NotNull] string format) { } + [Hyperion.Internal.NotNull] + public string Format { get; } + } + [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method | System.AttributeTargets.All)] + public sealed class AspMvcSuppressViewErrorAttribute : System.Attribute + { + public AspMvcSuppressViewErrorAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcTemplateAttribute : System.Attribute + { + public AspMvcTemplateAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcViewAttribute : System.Attribute + { + public AspMvcViewAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcViewComponentAttribute : System.Attribute + { + public AspMvcViewComponentAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AspMvcViewComponentViewAttribute : System.Attribute + { + public AspMvcViewComponentViewAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class AspMvcViewLocationFormatAttribute : System.Attribute + { + public AspMvcViewLocationFormatAttribute([Hyperion.Internal.NotNull] string format) { } + [Hyperion.Internal.NotNull] + public string Format { get; } + } + [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class AspRequiredAttributeAttribute : System.Attribute + { + public AspRequiredAttributeAttribute([Hyperion.Internal.NotNull] string attribute) { } + [Hyperion.Internal.NotNull] + public string Attribute { get; } + } + [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.All)] + public sealed class AspTypePropertyAttribute : System.Attribute + { + public AspTypePropertyAttribute(bool createConstructorReferences) { } + public bool CreateConstructorReferences { get; } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class AssertionConditionAttribute : System.Attribute + { + public AssertionConditionAttribute(Hyperion.Internal.AssertionConditionType conditionType) { } + public Hyperion.Internal.AssertionConditionType ConditionType { get; } + } + public enum AssertionConditionType + { + IS_TRUE = 0, + IS_FALSE = 1, + IS_NULL = 2, + IS_NOT_NULL = 3, + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.All)] + public sealed class AssertionMethodAttribute : System.Attribute + { + public AssertionMethodAttribute() { } + } + [Hyperion.Internal.BaseTypeRequired(typeof(System.Attribute))] + [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class BaseTypeRequiredAttribute : System.Attribute + { + public BaseTypeRequiredAttribute([Hyperion.Internal.NotNull] System.Type baseType) { } + [Hyperion.Internal.NotNull] + public System.Type BaseType { get; } + } + [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Parameter | System.AttributeTargets.Delegate | System.AttributeTargets.GenericParameter | System.AttributeTargets.All)] + public sealed class CanBeNullAttribute : System.Attribute + { + public CanBeNullAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Interface | System.AttributeTargets.All)] + public sealed class CannotApplyEqualityOperatorAttribute : System.Attribute + { + public CannotApplyEqualityOperatorAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.All)] + public sealed class CollectionAccessAttribute : System.Attribute + { + public CollectionAccessAttribute(Hyperion.Internal.CollectionAccessType collectionAccessType) { } + public Hyperion.Internal.CollectionAccessType CollectionAccessType { get; } + } + [System.Flags] + public enum CollectionAccessType + { + None = 0, + Read = 1, + ModifyExistingContent = 2, + UpdatedContent = 6, + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class ContractAnnotationAttribute : System.Attribute + { + public ContractAnnotationAttribute([Hyperion.Internal.NotNull] string contract) { } + public ContractAnnotationAttribute([Hyperion.Internal.NotNull] string contract, bool forceFullStates) { } + [Hyperion.Internal.NotNull] + public string Contract { get; } + public bool ForceFullStates { get; } + } + [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class HtmlAttributeValueAttribute : System.Attribute + { + public HtmlAttributeValueAttribute([Hyperion.Internal.NotNull] string name) { } + [Hyperion.Internal.NotNull] + public string Name { get; } + } + [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class HtmlElementAttributesAttribute : System.Attribute + { + public HtmlElementAttributesAttribute() { } + public HtmlElementAttributesAttribute([Hyperion.Internal.NotNull] string name) { } + [Hyperion.Internal.CanBeNull] + public string Name { get; } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Interface | System.AttributeTargets.All)] + public sealed class ImplicitNotNullAttribute : System.Attribute + { + public ImplicitNotNullAttribute() { } + } + [System.Flags] + public enum ImplicitUseKindFlags + { + Default = 7, + Access = 1, + Assign = 2, + InstantiatedWithFixedConstructorSignature = 4, + InstantiatedNoFixedConstructorSignature = 8, + } + [System.Flags] + public enum ImplicitUseTargetFlags + { + Default = 1, + Itself = 1, + Members = 2, + WithMembers = 3, + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class InstantHandleAttribute : System.Attribute + { + public InstantHandleAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class InvokerParameterNameAttribute : System.Attribute + { + public InvokerParameterNameAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Delegate | System.AttributeTargets.All)] + public sealed class ItemCanBeNullAttribute : System.Attribute + { + public ItemCanBeNullAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Delegate | System.AttributeTargets.All)] + public sealed class ItemNotNullAttribute : System.Attribute + { + public ItemNotNullAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.All)] + public sealed class LinqTunnelAttribute : System.Attribute + { + public LinqTunnelAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Module | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Parameter | System.AttributeTargets.Delegate | System.AttributeTargets.ReturnValue | System.AttributeTargets.GenericParameter | System.AttributeTargets.All)] + public sealed class LocalizationRequiredAttribute : System.Attribute + { + public LocalizationRequiredAttribute() { } + public LocalizationRequiredAttribute(bool required) { } + public bool Required { get; } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Parameter | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class MacroAttribute : System.Attribute + { + public MacroAttribute() { } + public int Editable { get; set; } + public string Expression { get; set; } + public string Target { get; set; } + } + [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.GenericParameter | System.AttributeTargets.All)] + public sealed class MeansImplicitUseAttribute : System.Attribute + { + public MeansImplicitUseAttribute() { } + public MeansImplicitUseAttribute(Hyperion.Internal.ImplicitUseKindFlags useKindFlags) { } + public MeansImplicitUseAttribute(Hyperion.Internal.ImplicitUseTargetFlags targetFlags) { } + public MeansImplicitUseAttribute(Hyperion.Internal.ImplicitUseKindFlags useKindFlags, Hyperion.Internal.ImplicitUseTargetFlags targetFlags) { } + [Hyperion.Internal.UsedImplicitly] + public Hyperion.Internal.ImplicitUseTargetFlags TargetFlags { get; } + [Hyperion.Internal.UsedImplicitly] + public Hyperion.Internal.ImplicitUseKindFlags UseKindFlags { get; } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.All)] + public sealed class MustUseReturnValueAttribute : System.Attribute + { + public MustUseReturnValueAttribute() { } + public MustUseReturnValueAttribute([Hyperion.Internal.NotNull] string justification) { } + [Hyperion.Internal.CanBeNull] + public string Justification { get; } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class NoEnumerationAttribute : System.Attribute + { + public NoEnumerationAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Module | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Parameter | System.AttributeTargets.Delegate | System.AttributeTargets.ReturnValue | System.AttributeTargets.GenericParameter | System.AttributeTargets.All)] + public sealed class NoReorder : System.Attribute + { + public NoReorder() { } + } + [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Parameter | System.AttributeTargets.Delegate | System.AttributeTargets.GenericParameter | System.AttributeTargets.All)] + public sealed class NotNullAttribute : System.Attribute + { + public NotNullAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.All)] + public sealed class NotifyPropertyChangedInvocatorAttribute : System.Attribute + { + public NotifyPropertyChangedInvocatorAttribute() { } + public NotifyPropertyChangedInvocatorAttribute([Hyperion.Internal.NotNull] string parameterName) { } + [Hyperion.Internal.CanBeNull] + public string ParameterName { get; } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class PathReferenceAttribute : System.Attribute + { + public PathReferenceAttribute() { } + public PathReferenceAttribute([Hyperion.Internal.NotNull] [Hyperion.Internal.PathReference] string basePath) { } + [Hyperion.Internal.CanBeNull] + public string BasePath { get; } + } + [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Parameter | System.AttributeTargets.GenericParameter | System.AttributeTargets.All)] + public sealed class ProvidesContextAttribute : System.Attribute + { + public ProvidesContextAttribute() { } + } + [Hyperion.Internal.MeansImplicitUse(Hyperion.Internal.ImplicitUseTargetFlags.Default | Hyperion.Internal.ImplicitUseTargetFlags.Itself | Hyperion.Internal.ImplicitUseTargetFlags.Members | Hyperion.Internal.ImplicitUseTargetFlags.WithMembers)] + public sealed class PublicAPIAttribute : System.Attribute + { + public PublicAPIAttribute() { } + public PublicAPIAttribute([Hyperion.Internal.NotNull] string comment) { } + [Hyperion.Internal.CanBeNull] + public string Comment { get; } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.All)] + public sealed class PureAttribute : System.Attribute + { + public PureAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class RazorDirectiveAttribute : System.Attribute + { + public RazorDirectiveAttribute([Hyperion.Internal.NotNull] string directive) { } + [Hyperion.Internal.NotNull] + public string Directive { get; } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.All)] + public sealed class RazorHelperCommonAttribute : System.Attribute + { + public RazorHelperCommonAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class RazorImportNamespaceAttribute : System.Attribute + { + public RazorImportNamespaceAttribute([Hyperion.Internal.NotNull] string name) { } + [Hyperion.Internal.NotNull] + public string Name { get; } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.All, AllowMultiple=true)] + public sealed class RazorInjectionAttribute : System.Attribute + { + public RazorInjectionAttribute([Hyperion.Internal.NotNull] string type, [Hyperion.Internal.NotNull] string fieldName) { } + [Hyperion.Internal.NotNull] + public string FieldName { get; } + [Hyperion.Internal.NotNull] + public string Type { get; } + } + [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.All)] + public sealed class RazorLayoutAttribute : System.Attribute + { + public RazorLayoutAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class RazorSectionAttribute : System.Attribute + { + public RazorSectionAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.All)] + public sealed class RazorWriteLiteralMethodAttribute : System.Attribute + { + public RazorWriteLiteralMethodAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.All)] + public sealed class RazorWriteMethodAttribute : System.Attribute + { + public RazorWriteMethodAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class RazorWriteMethodParameterAttribute : System.Attribute + { + public RazorWriteMethodParameterAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class RegexPatternAttribute : System.Attribute + { + public RegexPatternAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.All)] + public sealed class SourceTemplateAttribute : System.Attribute + { + public SourceTemplateAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Delegate | System.AttributeTargets.All)] + public sealed class StringFormatMethodAttribute : System.Attribute + { + public StringFormatMethodAttribute([Hyperion.Internal.NotNull] string formatParameterName) { } + [Hyperion.Internal.NotNull] + public string FormatParameterName { get; } + } + [System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.All)] + [System.Obsolete("Use [ContractAnnotation(\'=> halt\')] instead")] + public sealed class TerminatesProgramAttribute : System.Attribute + { + public TerminatesProgramAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Module | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Parameter | System.AttributeTargets.Delegate | System.AttributeTargets.ReturnValue | System.AttributeTargets.GenericParameter | System.AttributeTargets.All)] + public sealed class UsedImplicitlyAttribute : System.Attribute + { + public UsedImplicitlyAttribute() { } + public UsedImplicitlyAttribute(Hyperion.Internal.ImplicitUseKindFlags useKindFlags) { } + public UsedImplicitlyAttribute(Hyperion.Internal.ImplicitUseTargetFlags targetFlags) { } + public UsedImplicitlyAttribute(Hyperion.Internal.ImplicitUseKindFlags useKindFlags, Hyperion.Internal.ImplicitUseTargetFlags targetFlags) { } + public Hyperion.Internal.ImplicitUseTargetFlags TargetFlags { get; } + public Hyperion.Internal.ImplicitUseKindFlags UseKindFlags { get; } + } + [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.All)] + public sealed class ValueProviderAttribute : System.Attribute + { + public ValueProviderAttribute([Hyperion.Internal.NotNull] string name) { } + [Hyperion.Internal.NotNull] + public string Name { get; } + } + [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.All)] + public sealed class XamlItemBindingOfItemsControlAttribute : System.Attribute + { + public XamlItemBindingOfItemsControlAttribute() { } + } + [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.All)] + public sealed class XamlItemsControlAttribute : System.Attribute + { + public XamlItemsControlAttribute() { } + } +} +namespace Hyperion.SerializerFactories +{ + public abstract class ValueSerializerFactory + { + protected ValueSerializerFactory() { } + public abstract Hyperion.ValueSerializers.ValueSerializer BuildSerializer(Hyperion.Serializer serializer, System.Type type, System.Collections.Concurrent.ConcurrentDictionary typeMapping); + public abstract bool CanDeserialize(Hyperion.Serializer serializer, System.Type type); + public abstract bool CanSerialize(Hyperion.Serializer serializer, System.Type type); + } +} +namespace Hyperion.ValueSerializers +{ + public class DateTimeOffsetSerializer : Hyperion.ValueSerializers.SessionAwareByteArrayRequiringValueSerializer + { + public const byte Manifest = 10; + public const int Size = 16; + public static readonly Hyperion.ValueSerializers.DateTimeOffsetSerializer Instance; + public DateTimeOffsetSerializer() { } + public override int PreallocatedByteBufferSize { get; } + public static System.DateTimeOffset ReadValueImpl(System.IO.Stream stream, byte[] bytes) { } + } + public class KnownTypeObjectSerializer : Hyperion.ValueSerializers.ValueSerializer + { + public KnownTypeObjectSerializer(Hyperion.ValueSerializers.ObjectSerializer serializer, ushort typeIdentifier) { } + public override System.Type GetElementType() { } + public override object ReadValue(System.IO.Stream stream, Hyperion.DeserializerSession session) { } + public override void WriteManifest(System.IO.Stream stream, Hyperion.SerializerSession session) { } + public override void WriteValue(System.IO.Stream stream, object value, Hyperion.SerializerSession session) { } + } + public class ObjectReferenceSerializer : Hyperion.ValueSerializers.ValueSerializer + { + public const byte Manifest = 253; + public static readonly Hyperion.ValueSerializers.ObjectReferenceSerializer Instance; + public ObjectReferenceSerializer() { } + public override System.Type GetElementType() { } + public override object ReadValue(System.IO.Stream stream, Hyperion.DeserializerSession session) { } + public override void WriteManifest(System.IO.Stream stream, Hyperion.SerializerSession session) { } + public override void WriteValue(System.IO.Stream stream, object value, Hyperion.SerializerSession session) { } + } + public class ObjectSerializer : Hyperion.ValueSerializers.ValueSerializer + { + public const byte ManifestFull = 255; + public const byte ManifestIndex = 254; + public const byte ManifestVersion = 251; + public ObjectSerializer(System.Type type) { } + public override int PreallocatedByteBufferSize { get; } + public System.Type Type { get; } + public override System.Type GetElementType() { } + public void Initialize(Hyperion.ObjectReader reader, Hyperion.ObjectWriter writer, int preallocatedBufferSize = 0) { } + public override object ReadValue(System.IO.Stream stream, Hyperion.DeserializerSession session) { } + public override void WriteManifest(System.IO.Stream stream, Hyperion.SerializerSession session) { } + public override void WriteValue(System.IO.Stream stream, object value, Hyperion.SerializerSession session) { } + } + public abstract class SessionAwareByteArrayRequiringValueSerializer : Hyperion.ValueSerializers.ValueSerializer + { + protected SessionAwareByteArrayRequiringValueSerializer(byte manifest, System.Linq.Expressions.Expression>> writeStaticMethod, System.Linq.Expressions.Expression>> readStaticMethod) { } + public override sealed int EmitReadValue(Hyperion.Compilation.ICompiler c, int stream, int session, System.Reflection.FieldInfo field) { } + public override sealed void EmitWriteValue(Hyperion.Compilation.ICompiler c, int stream, int fieldValue, int session) { } + public override sealed System.Type GetElementType() { } + public override sealed object ReadValue(System.IO.Stream stream, Hyperion.DeserializerSession session) { } + public override sealed void WriteManifest(System.IO.Stream stream, Hyperion.SerializerSession session) { } + public override sealed void WriteValue(System.IO.Stream stream, object value, Hyperion.SerializerSession session) { } + } + public abstract class SessionIgnorantValueSerializer : Hyperion.ValueSerializers.ValueSerializer + { + protected SessionIgnorantValueSerializer(byte manifest, System.Linq.Expressions.Expression>> writeStaticMethod, System.Linq.Expressions.Expression>> readStaticMethod) { } + public override sealed int EmitReadValue(Hyperion.Compilation.ICompiler c, int stream, int session, System.Reflection.FieldInfo field) { } + public override sealed void EmitWriteValue(Hyperion.Compilation.ICompiler c, int stream, int fieldValue, int session) { } + public override sealed System.Type GetElementType() { } + public override sealed object ReadValue(System.IO.Stream stream, Hyperion.DeserializerSession session) { } + public override sealed void WriteManifest(System.IO.Stream stream, Hyperion.SerializerSession session) { } + public override sealed void WriteValue(System.IO.Stream stream, object value, Hyperion.SerializerSession session) { } + } + public class UnsupportedTypeException : System.Exception + { + public System.Type Type; + public UnsupportedTypeException(System.Type t, string msg) { } + } + public abstract class ValueSerializer + { + protected ValueSerializer() { } + public virtual int PreallocatedByteBufferSize { get; } + public virtual int EmitReadValue([Hyperion.Internal.NotNull] Hyperion.Compilation.ICompiler c, int stream, int session, [Hyperion.Internal.NotNull] System.Reflection.FieldInfo field) { } + public virtual void EmitWriteValue(Hyperion.Compilation.ICompiler c, int stream, int fieldValue, int session) { } + public abstract System.Type GetElementType(); + public abstract object ReadValue([Hyperion.Internal.NotNull] System.IO.Stream stream, [Hyperion.Internal.NotNull] Hyperion.DeserializerSession session); + public abstract void WriteManifest([Hyperion.Internal.NotNull] System.IO.Stream stream, [Hyperion.Internal.NotNull] Hyperion.SerializerSession session); + public abstract void WriteValue([Hyperion.Internal.NotNull] System.IO.Stream stream, object value, [Hyperion.Internal.NotNull] Hyperion.SerializerSession session); + protected static System.Reflection.MethodInfo GetStatic([Hyperion.Internal.NotNull] System.Linq.Expressions.LambdaExpression expression, [Hyperion.Internal.NotNull] System.Type expectedReturnType) { } + } +} \ No newline at end of file diff --git a/src/Hyperion.API.Tests/Hyperion.API.Tests.csproj b/src/Hyperion.API.Tests/Hyperion.API.Tests.csproj new file mode 100644 index 00000000..f81dcacc --- /dev/null +++ b/src/Hyperion.API.Tests/Hyperion.API.Tests.csproj @@ -0,0 +1,29 @@ + + + + + net461;netcoreapp3.1;net5.0 + + false + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/src/Hyperion.Akka.Integration.Tests/Hyperion.Akka.Integration.Tests.csproj b/src/Hyperion.Akka.Integration.Tests/Hyperion.Akka.Integration.Tests.csproj new file mode 100644 index 00000000..fc68d56d --- /dev/null +++ b/src/Hyperion.Akka.Integration.Tests/Hyperion.Akka.Integration.Tests.csproj @@ -0,0 +1,31 @@ + + + + + net461;netcoreapp3.1;net5.0 + + false + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/src/Hyperion.Akka.Integration.Tests/IntegrationSpec.cs b/src/Hyperion.Akka.Integration.Tests/IntegrationSpec.cs new file mode 100644 index 00000000..7ec81933 --- /dev/null +++ b/src/Hyperion.Akka.Integration.Tests/IntegrationSpec.cs @@ -0,0 +1,69 @@ +using System; +using Akka.Actor; +using Akka.Configuration; +using Akka.Serialization; +using Xunit; +using Akka.TestKit; +using Akka.TestKit.Xunit2; +using FluentAssertions; +using Xunit.Abstractions; +using AkkaSerializer = Akka.Serialization.Serializer; + +namespace Hyperion.Akka.Integration.Tests +{ + public class IntegrationSpec : TestKit + { + private static readonly Config Config = ConfigurationFactory.ParseString(@" + akka { + loglevel = WARNING + stdout-loglevel = WARNING + serialize-messages = on + actor { + serializers { + hyperion = ""Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"" + } + serialization-bindings { + ""System.Object"" = hyperion + } + } + } + # use random ports to avoid race conditions with binding contention + akka.remote.dot-netty.tcp.port = 0"); + + private readonly AkkaSerializer _serializer; + + public IntegrationSpec(ITestOutputHelper output) + : base(Config, nameof(IntegrationSpec), output) + { + _serializer = Sys.Serialization.FindSerializerForType(typeof(object)); + } + + [Fact] + public void Akka_should_load_Hyperion_correctly() + { + _serializer.Should().BeOfType(); + } + + [Fact] + public void Akka_HyperionSerializer_should_serialize_properly() + { + var myObject = new MyPocoClass + { + Name = "John Doe", + Count = 24 + }; + + var serialized = _serializer.ToBinary(myObject); + var deserialized = _serializer.FromBinary(serialized); + + deserialized.Name.Should().Be("John Doe"); + deserialized.Count.Should().Be(24); + } + + private class MyPocoClass + { + public string Name { get; set; } + public int Count { get; set; } + } + } +} diff --git a/src/Hyperion.Tests/CrossFrameworkSerializationTests.cs b/src/Hyperion.Tests/CrossFrameworkSerializationTests.cs index e3bddbcf..84c5a350 100644 --- a/src/Hyperion.Tests/CrossFrameworkSerializationTests.cs +++ b/src/Hyperion.Tests/CrossFrameworkSerializationTests.cs @@ -28,8 +28,8 @@ public CrossFrameworkSerializationTests(ITestOutputHelper log) // to convert netcore System.Drawing.Primitives to netfx // System.Drawing package. #if NETFX - _serializer = new Serializer(new SerializerOptions( - packageNameOverrides: new List> + _serializer = new Serializer(SerializerOptions.Default.WithPackageNameOverrides( + new List> { str => str.Contains("System.Drawing.Primitives") ? str.Replace(".Primitives", "") : str })); diff --git a/src/Hyperion.Tests/Hyperion.Tests.csproj b/src/Hyperion.Tests/Hyperion.Tests.csproj index fb290e00..74a9b28e 100644 --- a/src/Hyperion.Tests/Hyperion.Tests.csproj +++ b/src/Hyperion.Tests/Hyperion.Tests.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/Hyperion/SerializerOptions.cs b/src/Hyperion/SerializerOptions.cs index 098ecb4b..13532b63 100644 --- a/src/Hyperion/SerializerOptions.cs +++ b/src/Hyperion/SerializerOptions.cs @@ -16,6 +16,15 @@ namespace Hyperion { public class SerializerOptions { + public static readonly SerializerOptions Default = new SerializerOptions( + versionTolerance: false, + preserveObjectReferences: false, + surrogates: null, + serializerFactories: null, + knownTypes: null, + ignoreISerializable: false, + packageNameOverrides: null); + internal static List> DefaultPackageNameOverrides() { return new List> @@ -33,7 +42,6 @@ internal static List> DefaultPackageNameOverrides() } internal static readonly Surrogate[] EmptySurrogates = new Surrogate[0]; - private static readonly ValueSerializerFactory[] DefaultValueSerializerFactories = { @@ -72,7 +80,25 @@ internal static List> DefaultPackageNameOverrides() internal readonly List> CrossFrameworkPackageNameOverrides = DefaultPackageNameOverrides(); - public SerializerOptions(bool versionTolerance = false, bool preserveObjectReferences = false, IEnumerable surrogates = null, IEnumerable serializerFactories = null, IEnumerable knownTypes = null, bool ignoreISerializable = false, IEnumerable> packageNameOverrides = null) + [Obsolete] + public SerializerOptions( + bool versionTolerance = false, + bool preserveObjectReferences = false, + IEnumerable surrogates = null, + IEnumerable serializerFactories = null, + IEnumerable knownTypes = null, + bool ignoreISerializable = false) + : this(versionTolerance, preserveObjectReferences, surrogates, serializerFactories, knownTypes, ignoreISerializable, null) + { } + + public SerializerOptions( + bool versionTolerance, + bool preserveObjectReferences, + IEnumerable surrogates, + IEnumerable serializerFactories, + IEnumerable knownTypes, + bool ignoreISerializable, + IEnumerable> packageNameOverrides) { VersionTolerance = versionTolerance; Surrogates = surrogates?.ToArray() ?? EmptySurrogates; @@ -94,5 +120,38 @@ public SerializerOptions(bool versionTolerance = false, bool preserveObjectRefer if(packageNameOverrides != null) CrossFrameworkPackageNameOverrides.AddRange(packageNameOverrides); } + + public SerializerOptions WithVersionTolerance(bool versionTolerance) + => Copy(versionTolerance: versionTolerance); + public SerializerOptions WithPreserveObjectReferences(bool preserveObjectReferences) + => Copy(preserveObjectReferences: preserveObjectReferences); + public SerializerOptions WithSurrogates(IEnumerable surrogates) + => Copy(surrogates: surrogates); + public SerializerOptions WithSerializerFactory(IEnumerable serializerFactories) + => Copy(serializerFactories: serializerFactories); + public SerializerOptions WithKnownTypes(IEnumerable knownTypes) + => Copy(knownTypes: knownTypes); + public SerializerOptions WithIgnoreSerializable(bool ignoreISerializable) + => Copy(ignoreISerializable: ignoreISerializable); + public SerializerOptions WithPackageNameOverrides(IEnumerable> packageNameOverrides) + => Copy(packageNameOverrides: packageNameOverrides); + + private SerializerOptions Copy( + bool? versionTolerance = null, + bool? preserveObjectReferences = null, + IEnumerable surrogates = null, + IEnumerable serializerFactories = null, + IEnumerable knownTypes = null, + bool? ignoreISerializable = null, + IEnumerable> packageNameOverrides = null) + => new SerializerOptions( + versionTolerance ?? VersionTolerance, + preserveObjectReferences ?? PreserveObjectReferences, + surrogates ?? Surrogates, + serializerFactories ?? ValueSerializerFactories, + knownTypes ?? KnownTypes, + ignoreISerializable ?? IgnoreISerializable, + packageNameOverrides ?? CrossFrameworkPackageNameOverrides + ); } } \ No newline at end of file diff --git a/src/common.props b/src/common.props index f0ab5fde..dc709784 100644 --- a/src/common.props +++ b/src/common.props @@ -18,6 +18,9 @@ $(NoWarn);CS1591 + 1.4.18 + + 5.10.3 2.4.1 2.4.3 16.9.4