Tidy up namespaces

This commit is contained in:
Daniel Clark
2022-12-10 16:19:59 +00:00
parent 8bbff9bfd1
commit 6670e912ef
29 changed files with 118 additions and 124 deletions
@@ -1,24 +1,23 @@
using Avalonia.Data.Converters;
using System.Globalization;
namespace Toolkit.Foundation.Avalonia
namespace Toolkit.Foundation.Avalonia;
public static class EventArgsExtensions
{
public static class EventArgsExtensions
public static dynamic? GetEventArguments(this EventArgs args, string? path, IValueConverter? converter, object? converterParameter)
{
public static dynamic? GetEventArguments(this EventArgs args, string? path, IValueConverter? converter, object? converterParameter)
return !string.IsNullOrWhiteSpace(path) ? GetEventArgsPropertyPathValue(args, path) : converter is not null ? converter.Convert(args, typeof(object), converterParameter, CultureInfo.CurrentCulture) : (dynamic)args;
}
private static object GetEventArgsPropertyPathValue(object args, string path)
{
object? value = args;
if (path is { })
{
return !string.IsNullOrWhiteSpace(path) ? GetEventArgsPropertyPathValue(args, path) : converter is not null ? converter.Convert(args, typeof(object), converterParameter, CultureInfo.CurrentCulture) : (dynamic)args;
value = PropertyPathHelper.GetValue(args, path);
}
private static object GetEventArgsPropertyPathValue(object args, string path)
{
object? value = args;
if (path is { })
{
value = PropertyPathHelper.GetValue(args, path);
}
return value;
}
return value;
}
}
@@ -3,33 +3,32 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Toolkit.Framework.Foundation;
namespace Toolkit.Foundation.Avalonia
namespace Toolkit.Foundation.Avalonia;
public static class IHostBuilderExtensions
{
public static class IHostBuilderExtensions
public static IHostBuilder ConfigureTemplates(this IHostBuilder hostBuilder, Action<ITemplateBuilder> builderDelegate)
{
public static IHostBuilder ConfigureTemplates(this IHostBuilder hostBuilder, Action<ITemplateBuilder> builderDelegate)
hostBuilder.ConfigureServices((hostBuilderContext, serviceCollection) =>
{
hostBuilder.ConfigureServices((hostBuilderContext, serviceCollection) =>
TemplateBuilder? builder = new();
builderDelegate?.Invoke(builder);
serviceCollection.TryAddSingleton(builder.Descriptors);
serviceCollection.TryAddSingleton<ITemplateDescriptorProvider, TemplateDescriptorProvider>();
serviceCollection.TryAddSingleton<ITemplateFactory, TemplateFactory>();
serviceCollection.TryAddSingleton<INamedTemplateFactory, NamedTemplateFactory>();
serviceCollection.TryAddSingleton<ITypedDataTemplateFactory, TypedDataTemplateFactory>();
serviceCollection.TryAddSingleton<INamedDataTemplateFactory, NamedDataTemplateFactory>();
serviceCollection.TryAddSingleton<ITemplateSelector, TemplateSelector>();
foreach (ITemplateDescriptor? descriptor in builder.Descriptors)
{
TemplateBuilder? builder = new();
builderDelegate?.Invoke(builder);
serviceCollection.Add(new ServiceDescriptor(descriptor.TemplateType, descriptor.TemplateType, descriptor.Lifetime));
serviceCollection.Add(new ServiceDescriptor(descriptor.ContentType, descriptor.ContentType, descriptor.Lifetime));
}
});
serviceCollection.TryAddSingleton(builder.Descriptors);
serviceCollection.TryAddSingleton<ITemplateDescriptorProvider, TemplateDescriptorProvider>();
serviceCollection.TryAddSingleton<ITemplateFactory, TemplateFactory>();
serviceCollection.TryAddSingleton<INamedTemplateFactory, NamedTemplateFactory>();
serviceCollection.TryAddSingleton<ITypedDataTemplateFactory, TypedDataTemplateFactory>();
serviceCollection.TryAddSingleton<INamedDataTemplateFactory, NamedDataTemplateFactory>();
serviceCollection.TryAddSingleton<ITemplateSelector, TemplateSelector>();
foreach (ITemplateDescriptor? descriptor in builder.Descriptors)
{
serviceCollection.Add(new ServiceDescriptor(descriptor.TemplateType, descriptor.TemplateType, descriptor.Lifetime));
serviceCollection.Add(new ServiceDescriptor(descriptor.ContentType, descriptor.ContentType, descriptor.Lifetime));
}
});
return hostBuilder;
}
return hostBuilder;
}
}
@@ -4,19 +4,18 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Toolkit.Framework.Foundation;
namespace Toolkit.Foundation.Avalonia
namespace Toolkit.Foundation.Avalonia;
public static class IServiceCollectionExtensions
{
public static class IServiceCollectionExtensions
public static IServiceCollection AddNavigation(this IServiceCollection serviceCollection)
{
public static IServiceCollection AddNavigation(this IServiceCollection serviceCollection)
{
serviceCollection.TryAddSingleton<INavigationRouteDescriptorCollection, NavigationRouteDescriptorCollection>();
serviceCollection.TryAddSingleton<INavigationRouteDescriptorCollection, NavigationRouteDescriptorCollection>();
serviceCollection.TryAddTransient<Navigation<Frame>, FrameNavigation>();
serviceCollection.TryAddTransient<Navigation<ContentDialog>, ContentDialogNavigation>();
serviceCollection.TryAddTransient<Navigation<ContentControl>, ContentControlNavigation>();
serviceCollection.TryAddTransient<Navigation<Frame>, FrameNavigation>();
serviceCollection.TryAddTransient<Navigation<ContentDialog>, ContentDialogNavigation>();
serviceCollection.TryAddTransient<Navigation<ContentControl>, ContentControlNavigation>();
return serviceCollection;
}
return serviceCollection;
}
}
@@ -1,17 +1,16 @@
using Avalonia.Data;
namespace Toolkit.Foundation.Avalonia
{
public static class MarkupExtensions
{
public static Binding? ToBinding(this object value)
{
if (value is Binding)
{
return value as Binding;
}
namespace Toolkit.Foundation.Avalonia;
return new Binding { Mode = BindingMode.OneWay, Source = value };
public static class MarkupExtensions
{
public static Binding? ToBinding(this object value)
{
if (value is Binding)
{
return value as Binding;
}
return new Binding { Mode = BindingMode.OneWay, Source = value };
}
}
@@ -1,28 +1,27 @@
using Avalonia;
using Avalonia.Data;
namespace Toolkit.Foundation.Avalonia
namespace Toolkit.Foundation.Avalonia;
public static class PropertyPathHelper
{
public static class PropertyPathHelper
private static readonly Dummy dummy = new();
public static object GetValue(object args, string path)
{
private static readonly Dummy dummy = new();
public static object GetValue(object args, string path)
Binding binding = new(path)
{
Binding binding = new(path)
{
Mode = BindingMode.OneTime,
Source = args
};
Mode = BindingMode.OneTime,
Source = args
};
dummy.Bind(Dummy.ValueProperty, binding);
return dummy.GetValue(Dummy.ValueProperty);
}
dummy.Bind(Dummy.ValueProperty, binding);
return dummy.GetValue(Dummy.ValueProperty);
}
private class Dummy : AvaloniaObject
{
public static readonly StyledProperty<object> ValueProperty =
AvaloniaProperty.Register<Dummy, object>("Value");
}
private class Dummy : AvaloniaObject
{
public static readonly StyledProperty<object> ValueProperty =
AvaloniaProperty.Register<Dummy, object>("Value");
}
}