Steven Kirk 5 years ago
parent
commit
e84b5f8244
  1. 10
      src/Avalonia.Base/AvaloniaLocator.cs
  2. 9
      src/Avalonia.Controls/SystemDialog.cs

10
src/Avalonia.Base/AvaloniaLocator.cs

@ -125,6 +125,16 @@ namespace Avalonia
{ {
return (T?) resolver.GetService(typeof (T)); return (T?) resolver.GetService(typeof (T));
} }
public static object GetRequiredService(this IAvaloniaDependencyResolver resolver, Type t)
{
return resolver.GetService(t) ?? throw new InvalidOperationException($"Unable to locate '{t}'.");
}
public static T GetRequiredService<T>(this IAvaloniaDependencyResolver resolver)
{
return (T?)resolver.GetService(typeof(T)) ?? throw new InvalidOperationException($"Unable to locate '{typeof(T)}'.");
}
} }
} }

9
src/Avalonia.Controls/SystemDialog.cs

@ -66,8 +66,7 @@ namespace Avalonia.Controls
{ {
if(parent == null) if(parent == null)
throw new ArgumentNullException(nameof(parent)); throw new ArgumentNullException(nameof(parent));
var service = AvaloniaLocator.Current.GetService<ISystemDialogImpl>() ?? var service = AvaloniaLocator.Current.GetRequiredService<ISystemDialogImpl>();
throw new InvalidOperationException("Unable to locate ISystemDialogImpl.");
return (await service.ShowFileDialogAsync(this, parent) ?? return (await service.ShowFileDialogAsync(this, parent) ??
Array.Empty<string>()).FirstOrDefault(); Array.Empty<string>()).FirstOrDefault();
} }
@ -95,8 +94,7 @@ namespace Avalonia.Controls
{ {
if(parent == null) if(parent == null)
throw new ArgumentNullException(nameof(parent)); throw new ArgumentNullException(nameof(parent));
var service = AvaloniaLocator.Current.GetService<ISystemDialogImpl>() ?? var service = AvaloniaLocator.Current.GetRequiredService<ISystemDialogImpl>();
throw new InvalidOperationException("Unable to locate ISystemDialogImpl.");
return service.ShowFileDialogAsync(this, parent); return service.ShowFileDialogAsync(this, parent);
} }
} }
@ -125,8 +123,7 @@ namespace Avalonia.Controls
{ {
if(parent == null) if(parent == null)
throw new ArgumentNullException(nameof(parent)); throw new ArgumentNullException(nameof(parent));
var service = AvaloniaLocator.Current.GetService<ISystemDialogImpl>() ?? var service = AvaloniaLocator.Current.GetRequiredService<ISystemDialogImpl>();
throw new InvalidOperationException("Unable to locate ISystemDialogImpl.");
return service.ShowFolderDialogAsync(this, parent); return service.ShowFolderDialogAsync(this, parent);
} }
} }

Loading…
Cancel
Save