Skip to content

Commit

Permalink
Remove BinaryFormatter, Start Adding AOT Markup (#3943)
Browse files Browse the repository at this point in the history
<!-- Please be sure to read the
[Contribute](https://github.com/reactiveui/reactiveui#contribute)
section of the README -->

**What kind of change does this PR introduce?**
<!-- Bug fix, feature, docs update, ... -->

update

**What is the current behavior?**
<!-- You can also link to an open issue here. -->

BinaryFormatter is used for suspension

**What is the new behavior?**
<!-- If this is a feature change -->

Remove BinaryFormatter
Start adding AOT Markup

**What might this PR break?**

Suspension will fail to Deserialize
**** BREAKING CHANGE ****

**Please check if the PR fulfills these requirements**
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)

**Other information**:
  • Loading branch information
ChrisPulman authored Jan 23, 2025
1 parent 3c84778 commit 84be0b1
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,25 @@ namespace ReactiveUI
public class CreatesCommandBindingViaCommandParameter : ReactiveUI.ICreatesCommandBinding
{
public CreatesCommandBindingViaCommandParameter() { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls GetRuntimeProperty(string name)")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls GetRuntimeProperty(string name)")]
public System.IDisposable? BindCommandToObject(System.Windows.Input.ICommand? command, object? target, System.IObservable<object?> commandParameter) { }
public System.IDisposable? BindCommandToObject<TEventArgs>(System.Windows.Input.ICommand? command, object? target, System.IObservable<object?> commandParameter, string eventName) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls GetRuntimeProperty(string name)")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls GetRuntimeProperty(string name)")]
public int GetAffinityForObject(System.Type type, bool hasEventTarget) { }
}
public class CreatesCommandBindingViaEvent : ReactiveUI.ICreatesCommandBinding
{
public CreatesCommandBindingViaEvent() { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
public System.IDisposable? BindCommandToObject(System.Windows.Input.ICommand? command, object? target, System.IObservable<object?> commandParameter) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
public System.IDisposable? BindCommandToObject<TEventArgs>(System.Windows.Input.ICommand? command, object? target, System.IObservable<object?> commandParameter, string eventName) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
public int GetAffinityForObject(System.Type type, bool hasEventTarget) { }
}
public class DecimalToStringTypeConverter : ReactiveUI.IBindingTypeConverter, Splat.IEnableLogger
Expand All @@ -137,6 +147,8 @@ namespace ReactiveUI
public sealed class DefaultViewLocator : ReactiveUI.IViewLocator, Splat.IEnableLogger
{
public System.Func<string, string> ViewModelToViewFunc { get; set; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method is used to resolve views for view models.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
public ReactiveUI.IViewFor? ResolveView<T>(T? viewModel, string? contract = null) { }
}
public static class DependencyResolverMixins
Expand Down Expand Up @@ -369,7 +381,7 @@ namespace ReactiveUI
public interface ISuspensionDriver
{
System.IObservable<System.Reactive.Unit> InvalidateState();
System.IObservable<object> LoadState();
System.IObservable<object?> LoadState();
System.IObservable<System.Reactive.Unit> SaveState(object state);
}
public interface ISuspensionHost : ReactiveUI.IReactiveObject, Splat.IEnableLogger, System.ComponentModel.INotifyPropertyChanged, System.ComponentModel.INotifyPropertyChanging
Expand Down Expand Up @@ -813,6 +825,8 @@ namespace ReactiveUI
public static class Reflection
{
public static string ExpressionToPropertyNames(System.Linq.Expressions.Expression? expression) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls GetRuntimeMethods()")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls GetRuntimeMethods()")]
public static System.Type GetEventArgsTypeForEvent(System.Type type, string? eventName) { }
public static System.Func<object?, object?[]?, object?>? GetValueFetcherForProperty(System.Reflection.MemberInfo? member) { }
public static System.Func<object?, object?[]?, object?> GetValueFetcherOrThrow(System.Reflection.MemberInfo? member) { }
Expand All @@ -821,6 +835,8 @@ namespace ReactiveUI
public static bool IsStatic(this System.Reflection.PropertyInfo item) { }
public static System.Type? ReallyFindType(string? type, bool throwOnFailure) { }
public static System.Linq.Expressions.Expression Rewrite(System.Linq.Expressions.Expression? expression) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls GetTypeInfo()")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls GetTypeInfo()")]
public static void ThrowIfMethodsNotOverloaded(string callingTypeName, object targetObject, params string[] methodsToCheck) { }
public static bool TryGetAllValuesForPropertyChain(out ReactiveUI.IObservedChange<object, object?>[] changeValues, object? current, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> expressionChain) { }
public static bool TryGetValueForPropertyChain<TValue>(out TValue changeValue, object? current, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> expressionChain) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,25 @@ namespace ReactiveUI
public class CreatesCommandBindingViaCommandParameter : ReactiveUI.ICreatesCommandBinding
{
public CreatesCommandBindingViaCommandParameter() { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls GetRuntimeProperty(string name)")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls GetRuntimeProperty(string name)")]
public System.IDisposable? BindCommandToObject(System.Windows.Input.ICommand? command, object? target, System.IObservable<object?> commandParameter) { }
public System.IDisposable? BindCommandToObject<TEventArgs>(System.Windows.Input.ICommand? command, object? target, System.IObservable<object?> commandParameter, string eventName) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls GetRuntimeProperty(string name)")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls GetRuntimeProperty(string name)")]
public int GetAffinityForObject(System.Type type, bool hasEventTarget) { }
}
public class CreatesCommandBindingViaEvent : ReactiveUI.ICreatesCommandBinding
{
public CreatesCommandBindingViaEvent() { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
public System.IDisposable? BindCommandToObject(System.Windows.Input.ICommand? command, object? target, System.IObservable<object?> commandParameter) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
public System.IDisposable? BindCommandToObject<TEventArgs>(System.Windows.Input.ICommand? command, object? target, System.IObservable<object?> commandParameter, string eventName) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
public int GetAffinityForObject(System.Type type, bool hasEventTarget) { }
}
public class DecimalToStringTypeConverter : ReactiveUI.IBindingTypeConverter, Splat.IEnableLogger
Expand All @@ -137,6 +147,8 @@ namespace ReactiveUI
public sealed class DefaultViewLocator : ReactiveUI.IViewLocator, Splat.IEnableLogger
{
public System.Func<string, string> ViewModelToViewFunc { get; set; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method is used to resolve views for view models.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
public ReactiveUI.IViewFor? ResolveView<T>(T? viewModel, string? contract = null) { }
}
public static class DependencyResolverMixins
Expand Down Expand Up @@ -369,7 +381,7 @@ namespace ReactiveUI
public interface ISuspensionDriver
{
System.IObservable<System.Reactive.Unit> InvalidateState();
System.IObservable<object> LoadState();
System.IObservable<object?> LoadState();
System.IObservable<System.Reactive.Unit> SaveState(object state);
}
public interface ISuspensionHost : ReactiveUI.IReactiveObject, Splat.IEnableLogger, System.ComponentModel.INotifyPropertyChanged, System.ComponentModel.INotifyPropertyChanging
Expand Down Expand Up @@ -813,6 +825,8 @@ namespace ReactiveUI
public static class Reflection
{
public static string ExpressionToPropertyNames(System.Linq.Expressions.Expression? expression) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls GetRuntimeMethods()")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls GetRuntimeMethods()")]
public static System.Type GetEventArgsTypeForEvent(System.Type type, string? eventName) { }
public static System.Func<object?, object?[]?, object?>? GetValueFetcherForProperty(System.Reflection.MemberInfo? member) { }
public static System.Func<object?, object?[]?, object?> GetValueFetcherOrThrow(System.Reflection.MemberInfo? member) { }
Expand All @@ -821,6 +835,8 @@ namespace ReactiveUI
public static bool IsStatic(this System.Reflection.PropertyInfo item) { }
public static System.Type? ReallyFindType(string? type, bool throwOnFailure) { }
public static System.Linq.Expressions.Expression Rewrite(System.Linq.Expressions.Expression? expression) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Calls GetTypeInfo()")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Calls GetTypeInfo()")]
public static void ThrowIfMethodsNotOverloaded(string callingTypeName, object targetObject, params string[] methodsToCheck) { }
public static bool TryGetAllValuesForPropertyChain(out ReactiveUI.IObservedChange<object, object?>[] changeValues, object? current, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> expressionChain) { }
public static bool TryGetValueForPropertyChain<TValue>(out TValue changeValue, object? current, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> expressionChain) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ namespace ReactiveUI
public interface ISuspensionDriver
{
System.IObservable<System.Reactive.Unit> InvalidateState();
System.IObservable<object> LoadState();
System.IObservable<object?> LoadState();
System.IObservable<System.Reactive.Unit> SaveState(object state);
}
public interface ISuspensionHost : ReactiveUI.IReactiveObject, Splat.IEnableLogger, System.ComponentModel.INotifyPropertyChanged, System.ComponentModel.INotifyPropertyChanging
Expand Down
4 changes: 4 additions & 0 deletions src/ReactiveUI/Bindings/Command/CreatesCommandBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public static IDisposable BindCommandToObject(ICommand? command, object? target,
return ret;
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
[RequiresDynamicCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
#endif
public static IDisposable BindCommandToObject(ICommand? command, object? target, IObservable<object?> commandParameter, string? eventName)
{
var type = target!.GetType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace ReactiveUI;
public class CreatesCommandBindingViaCommandParameter : ICreatesCommandBinding
{
/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls GetRuntimeProperty(string name)")]
[RequiresDynamicCode("Calls GetRuntimeProperty(string name)")]
#endif
public int GetAffinityForObject(Type type, bool hasEventTarget)

Check warning on line 21 in src/ReactiveUI/Bindings/Command/CreatesCommandBindingViaCommandParameter.cs

View workflow job for this annotation

GitHub Actions / build / build

Member 'ReactiveUI.CreatesCommandBindingViaCommandParameter.GetAffinityForObject(Type, Boolean)' with 'RequiresDynamicCodeAttribute' implements interface member 'ReactiveUI.ICreatesCommandBinding.GetAffinityForObject(Type, Boolean)' without 'RequiresDynamicCodeAttribute'. 'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.
{
if (hasEventTarget)
Expand All @@ -35,6 +39,10 @@ public int GetAffinityForObject(Type type, bool hasEventTarget)
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls GetRuntimeProperty(string name)")]
[RequiresDynamicCode("Calls GetRuntimeProperty(string name)")]
#endif
public IDisposable? BindCommandToObject(ICommand? command, object? target, IObservable<object?> commandParameter)

Check warning on line 46 in src/ReactiveUI/Bindings/Command/CreatesCommandBindingViaCommandParameter.cs

View workflow job for this annotation

GitHub Actions / build / build

Member 'ReactiveUI.CreatesCommandBindingViaCommandParameter.BindCommandToObject(ICommand, Object, IObservable<Object>)' with 'RequiresDynamicCodeAttribute' implements interface member 'ReactiveUI.ICreatesCommandBinding.BindCommandToObject(ICommand, Object, IObservable<Object>)' without 'RequiresDynamicCodeAttribute'. 'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.
{
target.ArgumentNullExceptionThrowIfNull(nameof(target));
Expand Down
12 changes: 12 additions & 0 deletions src/ReactiveUI/Bindings/Command/CreatesCommandBindingViaEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class CreatesCommandBindingViaEvent : ICreatesCommandBinding
];

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
[RequiresDynamicCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
#endif
public int GetAffinityForObject(Type type, bool hasEventTarget)

Check warning on line 37 in src/ReactiveUI/Bindings/Command/CreatesCommandBindingViaEvent.cs

View workflow job for this annotation

GitHub Actions / build / build

Member 'ReactiveUI.CreatesCommandBindingViaEvent.GetAffinityForObject(Type, Boolean)' with 'RequiresDynamicCodeAttribute' implements interface member 'ReactiveUI.ICreatesCommandBinding.GetAffinityForObject(Type, Boolean)' without 'RequiresDynamicCodeAttribute'. 'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.
{
if (hasEventTarget)
Expand All @@ -45,6 +49,10 @@ public int GetAffinityForObject(Type type, bool hasEventTarget)
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
[RequiresDynamicCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
#endif
public IDisposable? BindCommandToObject(ICommand? command, object? target, IObservable<object?> commandParameter)

Check warning on line 56 in src/ReactiveUI/Bindings/Command/CreatesCommandBindingViaEvent.cs

View workflow job for this annotation

GitHub Actions / build / build

Member 'ReactiveUI.CreatesCommandBindingViaEvent.BindCommandToObject(ICommand, Object, IObservable<Object>)' with 'RequiresDynamicCodeAttribute' implements interface member 'ReactiveUI.ICreatesCommandBinding.BindCommandToObject(ICommand, Object, IObservable<Object>)' without 'RequiresDynamicCodeAttribute'. 'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.
{
target.ArgumentNullExceptionThrowIfNull(nameof(target));
Expand All @@ -61,6 +69,10 @@ public int GetAffinityForObject(Type type, bool hasEventTarget)
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
[RequiresDynamicCode("Calls System.Reflection.MethodInfo.MakeGenericMethod(params Type[])")]
#endif
public IDisposable? BindCommandToObject<TEventArgs>(ICommand? command, object? target, IObservable<object?> commandParameter, string eventName)

Check warning on line 76 in src/ReactiveUI/Bindings/Command/CreatesCommandBindingViaEvent.cs

View workflow job for this annotation

GitHub Actions / build / build

Member 'ReactiveUI.CreatesCommandBindingViaEvent.BindCommandToObject<TEventArgs>(ICommand, Object, IObservable<Object>, String)' with 'RequiresDynamicCodeAttribute' implements interface member 'ReactiveUI.ICreatesCommandBinding.BindCommandToObject<TEventArgs>(ICommand, Object, IObservable<Object>, String)' without 'RequiresDynamicCodeAttribute'. 'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.
#if MONO
where TEventArgs : EventArgs
Expand Down
8 changes: 8 additions & 0 deletions src/ReactiveUI/Expression/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ public static bool TrySetValueToPropertyChain<TValue>(object? target, IEnumerabl
/// <param name="eventName">The name of the event.</param>
/// <returns>The Type of the EventArgs to use.</returns>
/// <exception cref="Exception">If there is no event matching the name on the target type.</exception>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls GetRuntimeMethods()")]
[RequiresDynamicCode("Calls GetRuntimeMethods()")]
#endif
public static Type GetEventArgsTypeForEvent(Type type, string? eventName) // TODO: Create Test
{
type.ArgumentNullExceptionThrowIfNull(nameof(type));
Expand All @@ -354,6 +358,10 @@ public static Type GetEventArgsTypeForEvent(Type type, string? eventName) // TOD
/// <param name="targetObject">The object to check.</param>
/// <param name="methodsToCheck">The name of the methods to check.</param>
/// <exception cref="Exception">Thrown if the methods aren't overriden on the target object.</exception>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls GetTypeInfo()")]
[RequiresDynamicCode("Calls GetTypeInfo()")]
#endif
public static void ThrowIfMethodsNotOverloaded(string callingTypeName, object targetObject, params string[] methodsToCheck) // TODO: Create Test
{
var (methodName, methodImplementation) = methodsToCheck
Expand Down
4 changes: 2 additions & 2 deletions src/ReactiveUI/Interfaces/ISuspensionDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface ISuspensionDriver
/// Loads the application state from persistent storage.
/// </summary>
/// <returns>An object observable.</returns>
IObservable<object> LoadState();
IObservable<object?> LoadState();

/// <summary>
/// Saves the application state to disk.
Expand All @@ -30,4 +30,4 @@ public interface ISuspensionDriver
/// </summary>
/// <returns>A completed observable.</returns>
IObservable<Unit> InvalidateState();
}
}
2 changes: 1 addition & 1 deletion src/ReactiveUI/Mixins/AutoPersistHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ReactiveUI;
public static class AutoPersistHelper
{
private static readonly MemoizingMRUCache<Type, Dictionary<string, bool>> _persistablePropertiesCache = new(
(type, _) => type.GetTypeInfo().DeclaredProperties
static (type, _) => type.GetTypeInfo().DeclaredProperties
.Where(x => x.CustomAttributes.Any(y => typeof(DataMemberAttribute).GetTypeInfo().IsAssignableFrom(y.AttributeType.GetTypeInfo())))
.ToDictionary(k => k.Name, _ => true),
RxApp.SmallCacheLimit);
Expand Down
6 changes: 5 additions & 1 deletion src/ReactiveUI/PlatformRegistrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ namespace ReactiveUI;
public static class PlatformRegistrationManager
{
internal static RegistrationNamespace[] DefaultRegistrationNamespaces { get; } =
#if NET6_0_OR_GREATER
Enum.GetValues<RegistrationNamespace>();
#else
(RegistrationNamespace[])Enum.GetValues(typeof(RegistrationNamespace));
#endif

internal static RegistrationNamespace[] NamespacesToRegister { get; set; } = DefaultRegistrationNamespaces;

Expand All @@ -21,4 +25,4 @@ public static class PlatformRegistrationManager
/// </summary>
/// <param name="namespaces">The namespaces to register.</param>
public static void SetRegistrationNamespaces(params RegistrationNamespace[] namespaces) => NamespacesToRegister = namespaces;
}
}
18 changes: 12 additions & 6 deletions src/ReactiveUI/Platforms/android/BundleSuspensionDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// See the LICENSE file in the project root for full license information.

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.Json;

namespace ReactiveUI;

Expand All @@ -14,7 +14,11 @@ namespace ReactiveUI;
public class BundleSuspensionDriver : ISuspensionDriver
{
/// <inheritdoc/>
public IObservable<object> LoadState() // TODO: Create Test
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Deserialize<object>()")]
[RequiresDynamicCode("Calls Deserialize<object>()")]
#endif
public IObservable<object?> LoadState() // TODO: Create Test
{
try
{
Expand All @@ -24,7 +28,6 @@ public IObservable<object> LoadState() // TODO: Create Test
return Observable.Throw<object>(new Exception("New bundle, start from scratch"));
}

var serializer = new BinaryFormatter();
var buffer = AutoSuspendHelper.LatestBundle.GetByteArray("__state");

if (buffer is null)
Expand All @@ -34,7 +37,7 @@ public IObservable<object> LoadState() // TODO: Create Test

var st = new MemoryStream(buffer);

return Observable.Return(serializer.Deserialize(st));
return Observable.Return(JsonSerializer.Deserialize<object>(st));
}
catch (Exception ex)
{
Expand All @@ -43,13 +46,16 @@ public IObservable<object> LoadState() // TODO: Create Test
}

/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Calls Serialize<object>()")]
[RequiresDynamicCode("Calls Serialize<object>()")]
#endif
public IObservable<Unit> SaveState(object state) // TODO: Create Test
{
try
{
var serializer = new BinaryFormatter();
var st = new MemoryStream();

JsonSerializer.Serialize(st, state);
AutoSuspendHelper.LatestBundle?.PutByteArray("__state", st.ToArray());
return Observables.Unit;
}
Expand Down
Loading

0 comments on commit 84be0b1

Please sign in to comment.