当前位置: 首页>>代码示例>>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;未经允许,请勿转载。