コード例 #1
0
        public void TestConvertTo()
        {
            FileFiltersTypeConverter converter = new FileFiltersTypeConverter();

            Assert.AreEqual(true, converter.CanConvertTo(typeof(string)));
            Assert.AreEqual(true, converter.CanConvertTo(typeof(IList <IFileFilter>)));

            IList <IFileFilter> filters = new List <IFileFilter>()
            {
                FileFilter.Create("Test", "*.cs")
            };

            string filterStr = converter.ConvertTo(filters, typeof(string)) as string;

            Assert.IsNotNull(filterStr);
            Assert.AreEqual("Test|*.cs", filterStr);

            filterStr = converter.ConvertTo(filterStr, typeof(string)) as string;

            Assert.IsNotNull(filterStr);
            Assert.AreEqual("Test|*.cs", filterStr);

            filterStr = converter.ConvertFrom(null) as string;

            Assert.IsNull(filterStr);
        }
コード例 #2
0
        public void TestConvertFileFilterToString()
        {
            IFileFilter fileFilter = FileFilter.Create("Test", "*.cs");
            string      filterStr1 = FileFilterHelper.ConvertFileFilterToString(fileFilter);
            string      filterStr2 = filterStr1.ToString();

            Assert.AreEqual("Test|*.cs", filterStr1);
            Assert.AreEqual("Test|*.cs", filterStr2);
        }
コード例 #3
0
        /// <summary>
        /// Parses a file filter out of a filter portion string similar to the original .NET API
        /// (see https://docs.microsoft.com/de-de/dotnet/api/microsoft.win32.filedialog.filter?view=netframework-4.7.1#Microsoft_Win32_FileDialog_Filter).
        /// </summary>
        /// <param name="label">The label of the filter</param>
        /// <param name="filters">The filter portion string like: *.cs;*.xaml</param>
        /// <returns></returns>
        public static IFileFilter ParseFileFilter(string label, string filters)
        {
            if (string.IsNullOrWhiteSpace(label))
            {
                throw new ArgumentException(nameof(label) + " must not be empty");
            }

            IEnumerable <string> regularExpressions = ParseFilterRegularExpressions(filters);

            return(FileFilter.Create(label, filters, regularExpressions));
        }
コード例 #4
0
        public void TestConvertFileFiltersToString()
        {
            IList <IFileFilter> fileFilters = new List <IFileFilter>()
            {
                FileFilter.Create("Test", "*.cs"),
                FileFilter.Create("Web", "*.html;*.js")
            };

            string filtersStr = FileFilterHelper.ConvertFileFiltersToString(fileFilters);

            Assert.AreEqual("Test|*.cs|Web|*.html;*.js", filtersStr);
        }
コード例 #5
0
        public static string OpenOrSaveFile(BaseFileControl dialog, Window owner)
        {
            dialog.Filters = new List <IFileFilter>()
            {
                FileFilter.Create("JSON配置文件", "*.json")
            };
            dialog.GroupFoldersAndFiles = true;
            FileDialog win = new FileDialog();

            win.Content = dialog;
            win.Owner   = owner;
            string path = null;

            dialog.FileSelected += (s, e) =>
            {
                path = dialog.CurrentFile;
                win.Close();
            };
            win.ShowDialog();
            return(path);
        }