Click or drag to resize

DialogProvider Class

Provides way how to show system dialogs for files and folders.
Inheritance Hierarchy
SystemObject
  SniffCore.Navigation.DialogsDialogProvider

Namespace:  SniffCore.Navigation.Dialogs
Assembly:  SniffCore.Navigation (in SniffCore.Navigation.dll) Version: 1.6.0
Syntax
C#
public sealed class DialogProvider : IDialogProvider

The DialogProvider type exposes the following members.

Constructors
  NameDescription
Public methodDialogProvider
Initializes a new instance of the DialogProvider class
Top
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodShow(IBrowseFolderData)
Shows the browse folder dialog.
Public methodShow(IColorPickerData)
Shows the color picker dialog.
Public methodShow(IFontPickerData)
Shows the font picker dialog.
Public methodShow(IOpenFileData)
Shows the open file dialog.
Public methodShow(ISaveFileData)
Shows the save file dialog.
Public methodShow(Window, IBrowseFolderData)
Shows the browse folder dialog.
Public methodShow(Window, IColorPickerData)
Shows the color picker dialog.
Public methodShow(Window, IFontPickerData)
Shows the font picker dialog.
Public methodShow(Window, IOpenFileData)
Shows the open file dialog.
Public methodShow(Window, ISaveFileData)
Shows the save file dialog.
Public methodToString (Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodIsNullOrEmpty
Checks if the object is null or an empty string.
(Defined by ObjectEx.)
Public Extension MethodIsNullOrWhiteSpace
Checks if the object is null, an empty string or a string which consists of whitespace (or tabs) only.
(Defined by ObjectEx.)
Top
Examples
C#
public class ViewModel : ObservableObject
{
    private IDialogProvider _dialogProvider;

    public ViewModel(IDialogProvider dialogProvider)
    {
        _dialogProvider = dialogProvider;
    }

    public string GetFile()
    {
        var data = new OpenFileData
        {
            CheckFileExists = true,
            MultiSelect = false
        };

        if (_dialogProvider.Show(data))
            return data.FileName;

        return null;
    }
}
C#
[TestFixture]
public class ViewModelTests
{
    private Mock<IDialogProvider> _dialogProvider;
    private ViewModel _target;

    [SetUp]
    public void Setup()
    {
        _dialogProvider = new Mock<IDialogProvider>();
        _target = new ViewModel(_dialogProvider.Object);
    }

    [Test]
    public void GetFile_Called_ReturnsTheUserSelectedFile()
    {
        _dialogProvider.Setup(x => x.Show(Arg.Any<IOpenFileData>())
            .Callback(e => e.FileName = "filename")
            .Returns(true);

        var result = _target.GetFile();

        Assert.That(result, Is.EqualTo("filename"));
    }
}
See Also