Rework navigation so we can resolve by key now
This commit is contained in:
@@ -5,7 +5,7 @@ public class ContentFactory(IServiceProvider provider,
|
||||
IContentFactory
|
||||
{
|
||||
public object? Create(IContentTemplateDescriptor descriptor,
|
||||
object[] parameters)
|
||||
object?[] parameters)
|
||||
{
|
||||
object? content = parameters is { Length: > 0 }
|
||||
? factory.Create(descriptor.ContentType, args =>
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
public interface IContentFactory
|
||||
{
|
||||
object? Create(IContentTemplateDescriptor descriptor,
|
||||
object[] parameters);
|
||||
object?[] parameters);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,8 @@ public record NavigateEventArgs(string Route,
|
||||
EventHandler? Navigated = null,
|
||||
IDictionary<string, object>? Parameters = null);
|
||||
|
||||
public record NavigateEventArgs<TNavigation>(object Region,
|
||||
|
||||
public record NavigateTemplateEventArgs(object Region,
|
||||
object Template,
|
||||
object Content,
|
||||
object? Sender = null,
|
||||
|
||||
@@ -32,13 +32,17 @@ public class Navigation(IServiceProvider provider,
|
||||
is IContentTemplateDescriptor descriptor)
|
||||
{
|
||||
Dictionary<string, object>? arguments = parameters?.ToDictionary(x => x.Key, x => x.Value, StringComparer.InvariantCultureIgnoreCase) ?? [];
|
||||
object[]? resolvedArguments = parameters is not null ? [.. descriptor.ContentType
|
||||
.GetConstructors()
|
||||
.FirstOrDefault()?
|
||||
.GetParameters()
|
||||
.Select(x => x?.Name is not null && arguments
|
||||
.TryGetValue(x.Name, out object? argument) ? argument : default)
|
||||
.Where(argument => argument is not null)] : [];
|
||||
object?[] resolvedArguments = parameters is not null
|
||||
? descriptor.ContentType
|
||||
.GetConstructors()
|
||||
.FirstOrDefault()?
|
||||
.GetParameters()
|
||||
.Select(x =>
|
||||
x?.Name is not null && arguments is not null && arguments.TryGetValue(x.Name, out object? argument)
|
||||
? argument
|
||||
: null)
|
||||
.Where(argument => argument is not null)
|
||||
.ToArray() ?? [] : [];
|
||||
|
||||
if (provider.GetRequiredKeyedService(descriptor.TemplateType, descriptor.Key)
|
||||
is object template)
|
||||
@@ -67,16 +71,11 @@ public class Navigation(IServiceProvider provider,
|
||||
if (content is not null)
|
||||
{
|
||||
Type navigationType = region is Type type ? type : region.GetType();
|
||||
Type navigateEventType = typeof(NavigateEventArgs<>).MakeGenericType(navigationType);
|
||||
|
||||
if (Activator.CreateInstance(navigateEventType, [region, template, content, sender, parameters])
|
||||
is object navigateEvent)
|
||||
messenger.Send(new NavigateTemplateEventArgs(region, template, content, sender, parameters), navigationType.Name);
|
||||
if (currentSegmentIndex == segmentCount)
|
||||
{
|
||||
messenger.Send(navigateEvent, navigationType.Name);
|
||||
if (currentSegmentIndex == segmentCount)
|
||||
{
|
||||
navigated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
navigated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public partial class Observable(IServiceProvider provider,
|
||||
|
||||
public IServiceProvider Provider { get; } = provider;
|
||||
|
||||
public IMessenger Messenger { get; } = messenger;
|
||||
public new IMessenger Messenger { get; } = messenger;
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user