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