當前位置: 首頁>>代碼示例>>C#>>正文


C# DirectoryInfo.FirstOrDefault方法代碼示例

本文整理匯總了C#中System.IO.DirectoryInfo.FirstOrDefault方法的典型用法代碼示例。如果您正苦於以下問題:C# DirectoryInfo.FirstOrDefault方法的具體用法?C# DirectoryInfo.FirstOrDefault怎麽用?C# DirectoryInfo.FirstOrDefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.FirstOrDefault方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetPhotoshopSupportFiles

 private String GetPhotoshopSupportFiles()
 {
     String localePath = Path.Combine(PhotoshopInstallmentBasePath(), @"Locales");
     DirectoryInfo[] languageDirectorys = new DirectoryInfo(localePath).GetDirectories();
     DirectoryInfo localLanguageDirectory = languageDirectorys.FirstOrDefault();
     return Path.Combine(localLanguageDirectory.FullName, @"Support Files");
 }
開發者ID:JonasDralle,項目名稱:PhotoshopLanguageChanger,代碼行數:7,代碼來源:MainWindow.xaml.cs

示例2: Configure

        private void Configure(WidgetDefinition widget)
        {
            var files = new DirectoryInfo(Server.MapPath(widget.VirtualPath)).GetFiles();

            var iconFile = files.FirstOrDefault(f => f.Name.IgnoreCaseStartsWith("icon."));
            if (iconFile != null)
            {
                widget.IconUrl = UrlUtil.Combine(widget.VirtualPath, iconFile.Name);
            }

            widget.Editable = files.Any(f => f.Name.IgnoreCaseEquals("Editor.aspx"));

            var configFile = files.FirstOrDefault(f => f.Name.IgnoreCaseEquals("config.config"));
            if (configFile != null)
            {
                ApplyXmlConfig(widget, XDocument.Load(configFile.FullName).Root);
            }

            if (widget.DisplayName == null)
            {
                widget.DisplayName = new LocalizableText(String.Format("{{ Plugin={0}, Key={1} }}", widget.Plugin.Name, widget.Name));
            }
        }
開發者ID:sigcms,項目名稱:Seeger,代碼行數:23,代碼來源:DefaultWidgetLoader.cs

示例3: Init

        public void Init(PluginInitContext context)
        {
            //todo:move to common place
            var otherCompanyDlls = new DirectoryInfo(context.PluginMetadata.PluginDirecotry).GetFiles("*.dll");
            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
                {
                    var dll = otherCompanyDlls.FirstOrDefault(fi =>
                        {
                            try
                            {
                                Assembly assembly = Assembly.LoadFile(fi.FullName);
                                return assembly.FullName == args.Name;
                            }
                            catch
                            {
                                return false;
                            }
                        });
                    if (dll == null)
                    {
                        return null;
                    }

                    return Assembly.LoadFile(dll.FullName);
                };

            docsetBasePath = context.PluginMetadata.PluginDirecotry + @"Docset";
            if (!Directory.Exists(docsetBasePath))
                Directory.CreateDirectory(docsetBasePath);

            foreach (string path in Directory.GetDirectories(docsetBasePath))
            {
                string name = path.Substring(path.LastIndexOf('\\') + 1);
                string dbPath = path + @"\Contents\Resources\docSet.dsidx";
                string dbType = CheckTableExists("searchIndex", dbPath) ? "DASH" : "ZDASH";
                docs.Add(new Doc
                {
                    Name = name,
                    DBPath = dbPath,
                    DBType = dbType,
                    IconPath = TryGetIcon(name, path)
                });
            }
        }
開發者ID:pluto92,項目名稱:Wox,代碼行數:44,代碼來源:Main.cs

示例4: GetImageFromLocation

        protected FileSystemInfo GetImageFromLocation(string path, string filenameWithoutExtension)
        {
            try
            {
                var files = new DirectoryInfo(path)
                    .EnumerateFiles()
                    .Where(i =>
                    {
                        var fileName = Path.GetFileNameWithoutExtension(i.FullName);

                        if (!string.Equals(fileName, filenameWithoutExtension, StringComparison.OrdinalIgnoreCase))
                        {
                            return false;
                        }

                        var ext = i.Extension;

                        return !string.IsNullOrEmpty(ext) &&
                            BaseItem.SupportedImageExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
                    })
                    .ToList();

                return BaseItem.SupportedImageExtensions
                    .Select(ext => files.FirstOrDefault(i => string.Equals(ext, i.Extension, StringComparison.OrdinalIgnoreCase)))
                    .FirstOrDefault(file => file != null);
            }
            catch (DirectoryNotFoundException)
            {
                return null;
            }
        }
開發者ID:Brendon-MB3,項目名稱:MediaBrowser,代碼行數:31,代碼來源:ImageFromMediaLocationProvider.cs

示例5: GetCachedChannelItemMediaSources

        public IEnumerable<MediaSourceInfo> GetCachedChannelItemMediaSources(IChannelMediaItem item)
        {
            var filenamePrefix = item.Id.ToString("N");
            var parentPath = Path.Combine(ChannelDownloadPath, item.ChannelId);

            try
            {
                var files = new DirectoryInfo(parentPath).EnumerateFiles("*", SearchOption.TopDirectoryOnly);

                if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
                {
                    files = files.Where(i => EntityResolutionHelper.IsVideoFile(i.FullName));
                }
                else
                {
                    files = files.Where(i => EntityResolutionHelper.IsAudioFile(i.FullName));
                }

                var file = files
                    .FirstOrDefault(i => i.Name.StartsWith(filenamePrefix, StringComparison.OrdinalIgnoreCase));

                if (file != null)
                {
                    var cachedItem = _libraryManager.ResolvePath(file);

                    if (cachedItem != null)
                    {
                        var hasMediaSources = _libraryManager.GetItemById(cachedItem.Id) as IHasMediaSources;

                        if (hasMediaSources != null)
                        {
                            var source = hasMediaSources.GetMediaSources(true).FirstOrDefault();

                            if (source != null)
                            {
                                source.Type = MediaSourceType.Cache;
                                return new[] { source };
                            }
                        }
                    }
                }
            }
            catch (DirectoryNotFoundException)
            {

            }

            return new List<MediaSourceInfo>();
        }
開發者ID:jmarsh0507,項目名稱:MediaBrowser,代碼行數:49,代碼來源:ChannelManager.cs

示例6: AssertFolderContentsAreEqual

        public void AssertFolderContentsAreEqual(string folder1, string folder2)
        {
            if (folder1 == folder2)
            {
                Debug.WriteLine("folder1 and folder2 are the same folder.");
                return;
            }

            var folder1Files = new DirectoryInfo(folder1).GetFiles();
            var folder2Files = new DirectoryInfo(folder2).GetFiles();

            var filteredList = TableList.Except(new[] {"dbo.DatabaseLog"});


            foreach (var table in filteredList)
            {
                var fileName = string.Format("{0}.xml", table);
                var folder1File = folder1Files.FirstOrDefault(f1f => f1f.Name == fileName);
                Assert.IsNotNull(folder1File, string.Format("can't find {0} in folder {1}", fileName, folder1));
                var folder2File = folder2Files.FirstOrDefault(f2f => f2f.Name == fileName);
                Assert.IsNotNull(folder2File, string.Format("can't find {0} in folder {1}", fileName, folder2));
                Debug.WriteLine(string.Format("Comparing the contents of {0} to {1}...",
                    folder1File.FullName, folder2File.FullName));
                var folder1FileContents = File.ReadAllText(folder1File.FullName);
                var folder2FileContents = File.ReadAllText(folder2File.FullName);
                Assert.AreEqual(NormalizeText(folder1FileContents), NormalizeText(folder2FileContents));
            }
        }
開發者ID:ninerats,項目名稱:DataTools,代碼行數:28,代碼來源:BrundleFlyTest.cs


注:本文中的System.IO.DirectoryInfo.FirstOrDefault方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。