mirror of
https://github.com/evopro-ag/Sharp7Reactive.git
synced 2025-12-16 19:52:53 +00:00
Add non-generic CreateNotification method
This commit is contained in:
21
Sharp7.Rx/Utils/SignatureConverter.cs
Normal file
21
Sharp7.Rx/Utils/SignatureConverter.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Reactive.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Sharp7.Rx.Utils;
|
||||
|
||||
internal static class SignatureConverter
|
||||
{
|
||||
private static readonly MethodInfo convertToObjectObservableMethod =
|
||||
typeof(SignatureConverter)
|
||||
.GetMethods(BindingFlags.Public | BindingFlags.Static)
|
||||
.Single(m => m.Name == nameof(ConvertToObjectObservable) && m.GetGenericArguments().Length == 1);
|
||||
|
||||
public static IObservable<object> ConvertToObjectObservable<T>(IObservable<T> obs) => obs.Select(o => (object) o);
|
||||
|
||||
public static IObservable<object> ConvertToObjectObservable(object observable, Type sourceType)
|
||||
{
|
||||
var convertGeneric = convertToObjectObservableMethod.MakeGenericMethod(sourceType);
|
||||
|
||||
return convertGeneric.Invoke(null, [observable]) as IObservable<object>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user