Some refactoring
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
public record Activate
|
||||
{
|
||||
public static ActivateEventArgs<TValue> As<TValue>(TValue value) => new(value);
|
||||
public static ActivateEventArgs<TSender> As<TSender>(TSender sender) => new(sender);
|
||||
|
||||
public static ActivateEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
|
||||
}
|
||||
public static ActivateEventArgs<TSender> As<TSender>() where TSender : new() => new(new TSender());
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record ActivateEventArgs<TValue>(TValue? Value = default);
|
||||
public record ActivateEventArgs<TSender>(TSender? Sender = default);
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
public record Activated
|
||||
{
|
||||
public static ActivatedEventArgs<TValue> As<TValue>(TValue value) => new(value);
|
||||
public static ActivatedEventArgs<TSender> As<TSender>(TSender sender) => new(sender);
|
||||
|
||||
public static ActivatedEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
|
||||
public static ActivatedEventArgs<TSender> As<TSender>() where TSender : new() => new(new TSender());
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record ActivatedEventArgs<TValue>(TValue? Value = default);
|
||||
public record ActivatedEventArgs<TSender>(TSender? Sender = default);
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
public record Cancel
|
||||
{
|
||||
public static CancelEventArgs<TValue> As<TValue>(TValue value) =>
|
||||
new(value);
|
||||
public static CancelEventArgs<TSender> As<TSender>(TSender sender) => new(sender);
|
||||
|
||||
public static CancelEventArgs<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
public static CancelEventArgs<TSender> As<TSender>() where TSender : new() => new(new TSender());
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record CancelEventArgs<TValue>(TValue Value);
|
||||
public record CancelEventArgs<TSender>(TSender sender);
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
public record Changed
|
||||
{
|
||||
public static ChangedEventArgs<TValue> As<TValue>(TValue value) => new(value);
|
||||
public static ChangedEventArgs<TSender> As<TSender>(TSender sender) => new(sender);
|
||||
|
||||
public static ChangedEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
|
||||
public static ChangedEventArgs<TSender> As<TSender>() where TSender : new() => new(new TSender());
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record ChangedEventArgs<TValue>(TValue? Value = default);
|
||||
public record ChangedEventArgs<TSender>(TSender? Sender = default);
|
||||
@@ -59,7 +59,7 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, TAc
|
||||
|
||||
public Task Handle(ChangedEventArgs<TConfiguration> args)
|
||||
{
|
||||
if (args.Value is TConfiguration configuration)
|
||||
if (args.Sender is TConfiguration configuration)
|
||||
{
|
||||
Value = valueDelegate.Invoke(configuration);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, TDe
|
||||
|
||||
public Task Handle(ChangedEventArgs<TConfiguration> args)
|
||||
{
|
||||
if (args.Value is TConfiguration configuration)
|
||||
if (args.Sender is TConfiguration configuration)
|
||||
{
|
||||
Value = valueDelegate.Invoke(configuration);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ public class ConfigurationChangedHandler<TConfiguration, TValue>(ConfigurationVa
|
||||
{
|
||||
public Task Handle(ChangedEventArgs<TConfiguration> args)
|
||||
{
|
||||
if (args.Value is TConfiguration configuration)
|
||||
if (args.Sender is TConfiguration configuration)
|
||||
{
|
||||
if (configurationValue.TryUpdate(configuration, out TValue value))
|
||||
{
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
public record Create
|
||||
{
|
||||
public static CreateEventArgs<TValue> As<TValue>(TValue value, params object[] Parameters) =>
|
||||
new(value);
|
||||
public static CreateEventArgs<TSender> As<TSender>(TSender sender, params object[] parameters) =>
|
||||
new(sender, parameters);
|
||||
|
||||
public static CreateEventArgs<TValue> As<TValue>(params object[] Parameters) where TValue : new() =>
|
||||
new(new TValue());
|
||||
public static CreateEventArgs<TSender> As<TSender>(params object[] parameters) where TSender : new() =>
|
||||
new(new TSender(), parameters);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record CreateEventArgs<TValue>(TValue Value, params object[] Parameters);
|
||||
public record CreateEventArgs<TSender>(TSender? Sender = default,
|
||||
params object[] Parameters);
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
public record Created
|
||||
{
|
||||
public static CreatedEventArgs<TValue> As<TValue>(TValue value) =>
|
||||
new(value);
|
||||
public static CreatedEventArgs<TSender> As<TSender>(TSender sender) =>
|
||||
new(sender);
|
||||
|
||||
public static CreatedEventArgs<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
public static CreatedEventArgs<TSender> As<TSender>() where TSender : new() =>
|
||||
new(new TSender());
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record CreatedEventArgs<TValue>(TValue Value);
|
||||
public record CreatedEventArgs<TSender>(TSender? Sender = default);
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
public record Deactivated
|
||||
{
|
||||
public static DeactivatedEventArgs<TValue> As<TValue>(TValue value) => new(value);
|
||||
public static DeactivatedEventArgs<TSender> As<TSender>(TSender sender) => new(sender);
|
||||
|
||||
public static DeactivatedEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
|
||||
public static DeactivatedEventArgs<TSender> As<TSender>() where TSender : new() => new(new TSender());
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record DeactivatedEventArgs<TValue>(TValue? Value = default);
|
||||
public record DeactivatedEventArgs<TSender>(TSender? Sender = default);
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
public record Delete
|
||||
{
|
||||
public static DeleteEventArgs<TValue> As<TValue>(TValue value) =>
|
||||
new(value);
|
||||
public static DeleteEventArgs<TSender> As<TSender>(TSender sender) =>
|
||||
new(sender);
|
||||
|
||||
public static DeleteEventArgs<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
public static DeleteEventArgs<TSender> As<TSender>() where TSender : new() =>
|
||||
new(new TSender());
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record DeleteEventArgs<TValue>(TValue Value);
|
||||
public record DeleteEventArgs<TSender>(TSender? Sender = default);
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
public interface IMediator
|
||||
{
|
||||
Task<object?> Handle(object message,
|
||||
Task<object?> Handle(Type responseType,
|
||||
object message,
|
||||
object? key = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
@@ -11,7 +12,8 @@ public interface IMediator
|
||||
CancellationToken cancellationToken = default)
|
||||
where TMessage : notnull;
|
||||
|
||||
IAsyncEnumerable<object?> HandleManyAsync(object message,
|
||||
IAsyncEnumerable<object?> HandleManyAsync(Type responseType,
|
||||
object message,
|
||||
object? key = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
|
||||
@@ -27,41 +27,42 @@ public class Mediator(IHandlerProvider handlerProvider,
|
||||
return default;
|
||||
}
|
||||
|
||||
public async Task<object?> Handle(object message,
|
||||
public async Task<object?> Handle(Type responseType,
|
||||
object message,
|
||||
object? key = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
Type messageType = message.GetType();
|
||||
if (messageType.GetInterface(message.GetType().Name) is Type requestType &&
|
||||
requestType.GetGenericArguments().Length == 1)
|
||||
Type handlerWrapperType = typeof(HandlerWrapper<,>).MakeGenericType(message.GetType(), responseType);
|
||||
|
||||
List<object?> handlers = GetHandlers(message, handlerWrapperType, key);
|
||||
|
||||
foreach (object? handler in handlers)
|
||||
{
|
||||
Type responseType = requestType.GetGenericArguments()[0];
|
||||
Type handlerWrapperType = typeof(HandlerWrapper<,>).MakeGenericType(message.GetType(), responseType);
|
||||
|
||||
List<object?> handlers = GetHandlers(message, handlerWrapperType, key);
|
||||
|
||||
foreach (object? handler in handlers)
|
||||
MethodInfo? handleMethod = handler?.GetType().GetMethod("Handle", [messageType, typeof(CancellationToken)]);
|
||||
if (handleMethod != null)
|
||||
{
|
||||
MethodInfo? handleMethod = handler?.GetType().GetMethod("Handle", [messageType, typeof(CancellationToken)]);
|
||||
if (handleMethod != null)
|
||||
{
|
||||
return await (Task<object?>)handleMethod.Invoke(handler, new object[] { message, cancellationToken })!;
|
||||
}
|
||||
dynamic task = handleMethod.Invoke(handler, new object[] { message, cancellationToken })!;
|
||||
await task;
|
||||
|
||||
return task.Result;
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public async Task<List<object?>> HandleMany(object message,
|
||||
public async Task<List<object?>> HandleMany(Type responseType,
|
||||
object message,
|
||||
object? key = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
List<object?> responses = [];
|
||||
await foreach (object? response in HandleManyAsync(message, key, cancellationToken))
|
||||
await foreach (object? response in HandleManyAsync(responseType, message, key, cancellationToken))
|
||||
{
|
||||
responses.Add(response);
|
||||
}
|
||||
|
||||
return responses;
|
||||
}
|
||||
|
||||
@@ -79,26 +80,21 @@ public class Mediator(IHandlerProvider handlerProvider,
|
||||
return responses;
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<object?> HandleManyAsync(object message,
|
||||
object? key = null,
|
||||
public async IAsyncEnumerable<object?> HandleManyAsync(Type responseType,
|
||||
object message,
|
||||
object? key = null,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
Type messageType = message.GetType();
|
||||
Type handlerWrapperType = typeof(HandlerWrapper<,>).MakeGenericType(message.GetType(), responseType);
|
||||
|
||||
if (messageType.GetInterface(message.GetType().Name) is Type requestType &&
|
||||
requestType.GetGenericArguments().Length == 1)
|
||||
List<object?> handlers = GetHandlers(message, handlerWrapperType, key);
|
||||
foreach (object? handler in handlers)
|
||||
{
|
||||
Type responseType = requestType.GetGenericArguments()[0];
|
||||
Type handlerWrapperType = typeof(HandlerWrapper<,>).MakeGenericType(message.GetType(), responseType);
|
||||
|
||||
List<object?> handlers = GetHandlers(message, handlerWrapperType, key);
|
||||
foreach (object? handler in handlers)
|
||||
MethodInfo? handleMethod = handler?.GetType().GetMethod("Handle", [messageType, typeof(CancellationToken)]);
|
||||
if (handleMethod != null)
|
||||
{
|
||||
MethodInfo? handleMethod = handler?.GetType().GetMethod("Handle", [messageType, typeof(CancellationToken)]);
|
||||
if (handleMethod != null)
|
||||
{
|
||||
yield return await (Task<object?>)handleMethod.Invoke(handler, new object[] { message, cancellationToken })!;
|
||||
}
|
||||
yield return await (Task<object?>)handleMethod.Invoke(handler, new object[] { message, cancellationToken })!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
public record Move
|
||||
{
|
||||
public static MoveEventArgs<TValue> As<TValue>(int index, TValue value) =>
|
||||
new(index, value);
|
||||
public static MoveEventArgs<TSender> As<TSender>(int index, TSender sender) => new(index, sender);
|
||||
|
||||
public static InsertEventArgs<TValue> As<TValue>(int index) where TValue : new() =>
|
||||
new(index, new TValue());
|
||||
public static InsertEventArgs<TSender> As<TSender>(int index) where TSender : new() => new(index, new TSender());
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record MoveEventArgs<TValue>(int Index, TValue Value);
|
||||
public record MoveEventArgs<TSender>(int Index, TSender? Sender = default);
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record MoveToEventArgs<TValue>(int OldIndex, int NewIndex);
|
||||
public record MoveToEventArgs<TSender>(int OldIndex, int NewIndex);
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class NavigationScope(IPublisher publisher,
|
||||
IMediator mediator,
|
||||
IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
INavigationProvider navigationProvider,
|
||||
@@ -10,7 +11,7 @@ public class NavigationScope(IPublisher publisher,
|
||||
IContentTemplateDescriptorProvider contentTemplateDescriptorProvider) :
|
||||
INavigationScope
|
||||
{
|
||||
public void Navigate(string route,
|
||||
public async void Navigate(string route,
|
||||
object? sender = null,
|
||||
object? region = null,
|
||||
EventHandler? navigated = null,
|
||||
@@ -63,16 +64,34 @@ public class NavigationScope(IPublisher publisher,
|
||||
|
||||
if (region is not null)
|
||||
{
|
||||
if ((resolvedArguments is { Length: > 0 }
|
||||
? factory.Create(descriptor.ContentType, resolvedArguments)
|
||||
: provider.GetRequiredKeyedService(descriptor.ContentType, segment)) is object viewModel)
|
||||
Type createEventType = typeof(CreateEventArgs<>).MakeGenericType(descriptor.ContentType);
|
||||
|
||||
object? content = null;
|
||||
if (Activator.CreateInstance(createEventType, [null, resolvedArguments]) is object createEvent)
|
||||
{
|
||||
content = await mediator.Handle(descriptor.ContentType, createEvent, descriptor.Key);
|
||||
}
|
||||
|
||||
if (content is null)
|
||||
{
|
||||
if (resolvedArguments is { Length: > 0 })
|
||||
{
|
||||
content = factory.Create(descriptor.ContentType, resolvedArguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
content = provider.GetRequiredKeyedService(descriptor.ContentType, segment);
|
||||
}
|
||||
}
|
||||
|
||||
if (content is not null)
|
||||
{
|
||||
if (navigationProvider.Get(region is Type type ? type : region.GetType()) is INavigation navigation)
|
||||
{
|
||||
Type navigateType = typeof(NavigateEventArgs<>).MakeGenericType(navigation.Type);
|
||||
if (Activator.CreateInstance(navigateType, [region, view, viewModel, sender, parameters]) is object navigate)
|
||||
Type navigateEventType = typeof(NavigateEventArgs<>).MakeGenericType(navigation.Type);
|
||||
if (Activator.CreateInstance(navigateEventType, [region, view, content, sender, parameters]) is object navigateEvent)
|
||||
{
|
||||
publisher.Publish(navigate);
|
||||
publisher.Publish(navigateEvent);
|
||||
if (currentSegmentIndex == segmentCount)
|
||||
{
|
||||
navigated?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
public class Notify
|
||||
{
|
||||
public static NotifyEventArgs<TValue> As<TValue>(TValue value) =>
|
||||
new(value);
|
||||
public static NotifyEventArgs<TSender> As<TSender>(TSender sender) => new(sender);
|
||||
|
||||
public static NotifyEventArgs<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
public static NotifyEventArgs<TSender> As<TSender>() where TSender : new() => new(new TSender());
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record NotifyEventArgs<TValue>(TValue Value);
|
||||
public record NotifyEventArgs<TSender>(TSender? Sender = default);
|
||||
@@ -155,6 +155,12 @@ public partial class ObservableCollection<TItem> :
|
||||
return item;
|
||||
}
|
||||
|
||||
public void Clear(Action<ObservableCollection<TItem>> factory)
|
||||
{
|
||||
Clear();
|
||||
factory.Invoke(this);
|
||||
}
|
||||
|
||||
public void Add(TItem item)
|
||||
{
|
||||
int index = collection.Count;
|
||||
@@ -274,7 +280,7 @@ public partial class ObservableCollection<TItem> :
|
||||
{
|
||||
foreach (TItem item in this.ToList())
|
||||
{
|
||||
if (args.Value is not null && args.Value.Equals(item))
|
||||
if (args.Sender is not null && args.Sender.Equals(item))
|
||||
{
|
||||
Remove(item);
|
||||
}
|
||||
@@ -292,7 +298,7 @@ public partial class ObservableCollection<TItem> :
|
||||
{
|
||||
if (Activated)
|
||||
{
|
||||
if (args.Value is TItem item)
|
||||
if (args.Sender is TItem item)
|
||||
{
|
||||
Add(item);
|
||||
}
|
||||
@@ -340,7 +346,7 @@ public partial class ObservableCollection<TItem> :
|
||||
{
|
||||
if (Activated)
|
||||
{
|
||||
if (args.Value is TItem item)
|
||||
if (args.Sender is TItem item)
|
||||
{
|
||||
Move(args.Index, item);
|
||||
}
|
||||
@@ -357,7 +363,7 @@ public partial class ObservableCollection<TItem> :
|
||||
{
|
||||
if (Activated)
|
||||
{
|
||||
if (args.Value is TItem item)
|
||||
if (args.Sender is TItem item)
|
||||
{
|
||||
Replace(args.Index, item);
|
||||
}
|
||||
@@ -715,7 +721,8 @@ public partial class ObservableCollection<TViewModel, TKey, TValue> :
|
||||
partial void OnValueChanged(TValue value) => OnValueChanged();
|
||||
}
|
||||
|
||||
public class ObservableCollection : ObservableCollection<IDisposable>
|
||||
public class ObservableCollection :
|
||||
ObservableCollection<IDisposable>
|
||||
{
|
||||
public ObservableCollection(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
public record Remove
|
||||
{
|
||||
public static RemoveEventArgs<TValue> As<TValue>(TValue value) =>
|
||||
new(value);
|
||||
public static RemoveEventArgs<TSender> As<TSender>(TSender sender) => new(sender);
|
||||
|
||||
public static RemoveEventArgs<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
public static RemoveEventArgs<TSender> As<TSender>() where TSender : new() => new(new TSender());
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record RemoveEventArgs<TValue>(TValue Value);
|
||||
|
||||
public record RemoveAndInsertEventArgs<TValue>(TValue Value);
|
||||
public record RemoveEventArgs<TSender>(TSender? Sender = default);
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
public record Replace
|
||||
{
|
||||
public static ReplaceEventArgs<TValue> As<TValue>(int index, TValue value) =>
|
||||
new(index, value);
|
||||
public static ReplaceEventArgs<TSender> As<TSender>(int index, TSender sender) => new(index, sender);
|
||||
|
||||
public static ReplaceEventArgs<TValue> As<TValue>(int index) where TValue : new() =>
|
||||
new(index, new TValue());
|
||||
public static ReplaceEventArgs<TSender> As<TSender>(int index) where TSender : new() => new(index, new TSender());
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record ReplaceEventArgs<TValue>(int Index, TValue Value);
|
||||
public record ReplaceEventArgs<TSender>(int Index, TSender? Sender = default);
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record RequestEventArgs<TValue>(TValue Value);
|
||||
public record RequestEventArgs<TValue>(TValue? Value = default);
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
public record Synchronize
|
||||
{
|
||||
public static SynchronizeEventArgs<TValue, TOptions> As<TValue, TOptions>(TOptions options)
|
||||
where TOptions : class => new(options);
|
||||
public static SynchronizeEventArgs<TValue, TOptions> As<TValue, TOptions>(TOptions options) => new(options);
|
||||
|
||||
public static SynchronizeEventArgs<TValue> As<TValue>() =>
|
||||
new();
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public static class TupleExtensions
|
||||
{
|
||||
public static (T1, T2) CreateValueTuple<T1, T2>(this object[] parameters) => (
|
||||
(T1)Convert.ChangeType(parameters[0], typeof(T1)),
|
||||
(T2)Convert.ChangeType(parameters[1], typeof(T2))
|
||||
);
|
||||
|
||||
public static (T1, T2, T3) CreateValueTuple<T1, T2, T3>(this object[] parameters) => (
|
||||
(T1)Convert.ChangeType(parameters[0], typeof(T1)),
|
||||
(T2)Convert.ChangeType(parameters[1], typeof(T2)),
|
||||
(T3)Convert.ChangeType(parameters[2], typeof(T3))
|
||||
);
|
||||
|
||||
public static (T1, T2, T3, T4) CreateValueTuple<T1, T2, T3, T4>(this object[] parameters) => (
|
||||
(T1)Convert.ChangeType(parameters[0], typeof(T1)),
|
||||
(T2)Convert.ChangeType(parameters[1], typeof(T2)),
|
||||
(T3)Convert.ChangeType(parameters[2], typeof(T3)),
|
||||
(T4)Convert.ChangeType(parameters[3], typeof(T4))
|
||||
);
|
||||
public static (T1, T2, T3, T4, T5) CreateValueTuple<T1, T2, T3, T4, T5>(this object[] parameters) => (
|
||||
(T1)Convert.ChangeType(parameters[0], typeof(T1)),
|
||||
(T2)Convert.ChangeType(parameters[1], typeof(T2)),
|
||||
(T3)Convert.ChangeType(parameters[2], typeof(T3)),
|
||||
(T4)Convert.ChangeType(parameters[3], typeof(T4)),
|
||||
(T5)Convert.ChangeType(parameters[4], typeof(T5))
|
||||
);
|
||||
|
||||
public static (T1, T2, T3, T4, T5, T6) CreateValueTuple<T1, T2, T3, T4, T5, T6>(this object[] parameters) =>
|
||||
((T1)Convert.ChangeType(parameters[0], typeof(T1)),
|
||||
(T2)Convert.ChangeType(parameters[1], typeof(T2)),
|
||||
(T3)Convert.ChangeType(parameters[2], typeof(T3)),
|
||||
(T4)Convert.ChangeType(parameters[3], typeof(T4)),
|
||||
(T5)Convert.ChangeType(parameters[4], typeof(T5)),
|
||||
(T6)Convert.ChangeType(parameters[5], typeof(T6))
|
||||
);
|
||||
|
||||
public static (T1, T2, T3, T4, T5, T6, T7) CreateValueTuple<T1, T2, T3, T4, T5, T6, T7>(this object[] parameters) =>
|
||||
((T1)Convert.ChangeType(parameters[0], typeof(T1)),
|
||||
(T2)Convert.ChangeType(parameters[1], typeof(T2)),
|
||||
(T3)Convert.ChangeType(parameters[2], typeof(T3)),
|
||||
(T4)Convert.ChangeType(parameters[3], typeof(T4)),
|
||||
(T5)Convert.ChangeType(parameters[4], typeof(T5)),
|
||||
(T6)Convert.ChangeType(parameters[5], typeof(T6)),
|
||||
(T7)Convert.ChangeType(parameters[6], typeof(T7))
|
||||
);
|
||||
|
||||
public static (T1, T2, T3, T4, T5, T6, T7, T8) CreateValueTuple<T1, T2, T3, T4, T5, T6, T7, T8>(this object[] parameters) =>
|
||||
((T1)Convert.ChangeType(parameters[0], typeof(T1)),
|
||||
(T2)Convert.ChangeType(parameters[1], typeof(T2)),
|
||||
(T3)Convert.ChangeType(parameters[2], typeof(T3)),
|
||||
(T4)Convert.ChangeType(parameters[3], typeof(T4)),
|
||||
(T5)Convert.ChangeType(parameters[4], typeof(T5)),
|
||||
(T6)Convert.ChangeType(parameters[5], typeof(T6)),
|
||||
(T7)Convert.ChangeType(parameters[6], typeof(T7)),
|
||||
(T8)Convert.ChangeType(parameters[7], typeof(T8))
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user