C# Path.HasExtension的代码示例

通过代码示例来学习C# Path.HasExtension方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


Path.HasExtension是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的Path.HasExtension() 已经帮大家高亮显示了,大家可以重点学习Path.HasExtension() 方法的写法,从而快速掌握该方法的应用。

Path.HasExtension的代码示例1 - SaveActiveFile()

    using System.IO;

        #endregion

        #region SaveFile

        public void SaveActiveFile(bool UseSaveDialog = true, bool UseCompressDialog = true)
        {
            if (ActiveMdiChild != null)
            {
                if (ActiveMdiChild is ObjectEditor)
                    SaveNodeFormats((ObjectEditor)ActiveMdiChild, UseSaveDialog, UseCompressDialog);
                else
                {
                    var format = GetActiveIFileFormat();

                    if (!format.CanSave)
                        return;

                    if (ActiveMdiChild is IFIleEditor)
                    {
                       // if (((IFIleEditor)ActiveMdiChild).GetFileFormats().Count > 0)
                        //    ((IFIleEditor)ActiveMdiChild).BeforeFileSaved();
                    }

                    string FileName = format.FilePath;
                    if (!File.Exists(FileName))
                        UseSaveDialog = true;

                    if (UseSaveDialog)
                    {
                        if (format is VGAdudioFile)
                        {
                            SaveFileDialog sfd = new SaveFileDialog();

                            List formats = new List();
                            foreach (VGAdudioFile fileFormat in FileManager.GetVGAudioFileFormats())
                            {
                                formats.Add((IFileFormat)fileFormat);
                            }
                            sfd.Filter = Utils.GetAllFilters(formats);
                            sfd.DefaultExt = Path.GetExtension(format.FilePath);

                            if (sfd.ShowDialog() != DialogResult.OK)
                                return;

                            foreach (var fileFormat in formats)
                            {
                                foreach (var ext in format.Extension)
                                {
                                    if (Utils.HasExtension(sfd.FileName, ext))
                                    {
                                        ((VGAdudioFile)format).Format = fileFormat;
                                    }
                                }
                            }

                            FileName = sfd.FileName;
                        }
                        else
                        {
                            SaveFileDialog sfd = new SaveFileDialog();
                            sfd.Filter = Utils.GetAllFilters(format);
                            sfd.FileName = format.FileName;
                            sfd.DefaultExt = Path.GetExtension(format.FilePath);

                            if (sfd.ShowDialog() != DialogResult.OK)
                                return;

                            FileName = sfd.FileName;
                        }
                    }
                    Cursor.Current = Cursors.WaitCursor;
                    STFileSaver.SaveFileFormat(format, FileName, UseCompressDialog);
                    Cursor.Current = Cursors.Default;
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:78,代码来源:MainForm.cs

在SaveActiveFile()方法中,Path的代码示例类中的HasExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.HasExtension的代码示例2 - GenerateOptions()

    using System.IO;

        private Options.ExplicitOptions GenerateOptions(XCodeGenerationContext context)
        {
            var project = context.Project;
            var conf = context.Configuration;
            var options = new Options.ExplicitOptions();
            var cmdLineOptions = new ProjectOptionsGenerator.VcxprojCmdLineOptions();
            context.Options = options;
            context.CommandLineOptions = cmdLineOptions;

            options["TargetName"] = XCodeUtil.XCodeFormatSingleItem(conf.Target.Name);

            // TODO: really not ideal, refactor and move the properties we need from it someplace else
            var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform);

            FillIncludeDirectoriesOptions(context, platformVcxproj);
            FillCompilerOptions(context, platformVcxproj);

            context.Options["GenerateMapFile"] = RemoveLineTag;
            platformVcxproj.SelectLinkerOptions(context);

            var libFiles = new OrderableStrings(conf.LibraryFiles);
            libFiles.AddRange(conf.DependenciesBuiltTargetsLibraryFiles);
            libFiles.AddRange(conf.DependenciesOtherLibraryFiles);
            libFiles.Sort();

            var linkerOptions = new Strings(conf.AdditionalLinkerOptions);

            var linkObjC = Options.GetObject(conf);
            if (linkObjC == Options.XCode.Linker.LinkObjC.Enable)
                linkerOptions.Add("-ObjC");

            // linker(ld) of Xcode: only accept libfilename without prefix and suffix.
            linkerOptions.AddRange(libFiles.Select(library =>
            {
                // deal with full library path: add libdir and libname
                if (Path.IsPathFullyQualified(library))
                {
                    conf.LibraryPaths.Add(Path.GetDirectoryName(library));
                    library = Path.GetFileName(library);
                }

                if (Path.HasExtension(library) &&
                    ((Path.GetExtension(library).EndsWith(".a", StringComparison.OrdinalIgnoreCase) ||
                      Path.GetExtension(library).EndsWith(".dylib", StringComparison.OrdinalIgnoreCase)
                    )))
                {
                    library = Path.GetFileNameWithoutExtension(library);
                    if (library.StartsWith("lib"))
                        library = library.Remove(0, 3);
                }
                return $"-l{library}";
            }));

            SelectAdditionalLibraryDirectoriesOption(context, platformVcxproj);

            // this is needed to make sure the output dynamic library with proper prefix
            if (conf.Output == Project.Configuration.OutputType.Dll)
                options["ExecutablePrefix"] = "lib";
            else
                options["ExecutablePrefix"] = RemoveLineTag;

            if (conf.DefaultOption == Options.DefaultTarget.Debug)
                conf.Defines.Add("_DEBUG");
            else // Release
                conf.Defines.Add("NDEBUG");

            options["PreprocessorDefinitions"] = XCodeUtil.XCodeFormatList(conf.Defines, 4, forceQuotes: true);
            options["CompilerOptions"] = XCodeUtil.XCodeFormatList(Enumerable.Concat(conf.AdditionalCompilerOptions, conf.AdditionalCompilerOptimizeOptions), 4, forceQuotes: true);
            if (conf.AdditionalLibrarianOptions.Any())
                throw new NotImplementedException(nameof(conf.AdditionalLibrarianOptions) + " not supported with XCode generator");
            options["LinkerOptions"] = XCodeUtil.XCodeFormatList(linkerOptions, 4, forceQuotes: true);
            return options;
        }
    

开发者ID:ubisoft,项目名称:Sharpmake,代码行数:75,代码来源:XCodeProj.cs

在GenerateOptions()方法中,Path的代码示例类中的HasExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.HasExtension的代码示例3 - BuildDict()

    using System.IO;
        [ArgumentCommand(LongDesc = "Creates a ResourceDictionary with the svg-Images of a folder")]
        public int BuildDict(
            [ArgumentParam(Aliases = "i", Desc = "dir to the SVGs", LongDesc = "specify folder of the graphic files to process")]
            string inputdir,
            [ArgumentParam(Aliases = "o", LongDesc = "Name for the xaml outputfile")]
            string outputname,
            [ArgumentParam(DefaultValue = null, ExplicitNeeded = false, LongDesc = "folder for the xaml-Output, optional, default: folder of svgs")]
            string outputdir = null,
            [ArgumentParam(LongDesc = "Builds a htmlfile to browse the svgs, optional, default true")]
            bool buildhtmlfile = true,
            [ArgumentParam(DefaultValue = null, ExplicitNeeded = false, LongDesc = "Prefix to name all items of this file, optional, default: no prefix")]
            string nameprefix = null,
            [ArgumentParam(DefaultValue = false, ExplicitNeeded = false, LongDesc = "If true, es explicit ResourceKey File is created, default: false", ExplicitWantedArguments = "resKeyNS,resKeyNSName")]
            bool useComponentResKeys = false,
            [ArgumentParam(DefaultValue = null, ExplicitNeeded = false, LongDesc = "Namespace to use with UseResKey")]
            string compResKeyNS = null,
            [ArgumentParam(DefaultValue = null, ExplicitNeeded = false, LongDesc = "name of Namespace to use with UseResKey" )]
            string compResKeyNSName = null,
            [ArgumentParam(DefaultValue = false, ExplicitNeeded = false, LongDesc = "If true, PixelsPerDip is filtered to ensure compatibility for < 4.6.2, default: false")]
            bool filterPixelsPerDip = false,
            [ArgumentParam(DefaultValue = false, ExplicitNeeded = false, LongDesc = "Recursive goes through inputdir subfolders")]
            bool handleSubFolders = false
            )
        {
            Console.WriteLine("Building resource dictionary...");
            var outFileName = Path.Combine(outputdir ?? inputdir, outputname);
            if (!Path.HasExtension(outFileName))
                outFileName = Path.ChangeExtension(outFileName, ".xaml");

            var resKeyInfo = new ResKeyInfo
            {
                Name = null,
                XamlName = Path.GetFileNameWithoutExtension(outputname),
                Prefix = nameprefix,
                UseComponentResKeys = useComponentResKeys,
                NameSpace = compResKeyNS,
                NameSpaceName = compResKeyNSName,
            };

            File.WriteAllText(outFileName, ConverterLogic.SvgDirToXaml(inputdir, resKeyInfo, null, filterPixelsPerDip, handleSubFolders));
            Console.WriteLine("xaml written to: {0}", outFileName);

            if (buildhtmlfile)
            {
                var htmlFilePath = Path.Combine(inputdir,
                    Path.GetFileNameWithoutExtension(outputname));
                var files = ConverterLogic.SvgFilesFromFolder(inputdir);
                BuildHtmlBrowseFile(files, htmlFilePath);
            }
            return 0; //no Error
        }
    

开发者ID:BerndK,项目名称:SvgToXaml,代码行数:52,代码来源:CmdLineTarget.cs

在BuildDict()方法中,Path的代码示例类中的HasExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.HasExtension的代码示例4 - SetupProjectGlobalPropertiesThatAllProjectSystemsMustSet()

    using System.IO;

        /// 
        /// Setup the global properties for project instance.
        /// 
        private void SetupProjectGlobalPropertiesThatAllProjectSystemsMustSet()
        {
            string solutionDirectory = null;
            string solutionFile = null;

            if(this.Site.GetService(typeof(SVsSolution)) is IVsSolution solution)
            {
                // We do not want to throw. If we cannot set the solution related constants we set them to empty string.
                solution.GetSolutionInfo(out solutionDirectory, out solutionFile, out _);
            }

            if (solutionDirectory == null)
            {
                solutionDirectory = String.Empty;
            }

            if (solutionFile == null)
            {
                solutionFile = String.Empty;
            }

            string solutionFileName = (solutionFile.Length == 0) ? String.Empty : Path.GetFileName(solutionFile);

            string solutionName = (solutionFile.Length == 0) ? String.Empty : Path.GetFileNameWithoutExtension(solutionFile);

            string solutionExtension = String.Empty;
            if (solutionFile.Length > 0 && Path.HasExtension(solutionFile))
            {
                solutionExtension = Path.GetExtension(solutionFile);
            }

            this.buildProject.SetGlobalProperty(GlobalProperty.SolutionDir.ToString(), solutionDirectory);
            this.buildProject.SetGlobalProperty(GlobalProperty.SolutionPath.ToString(), solutionFile);
            this.buildProject.SetGlobalProperty(GlobalProperty.SolutionFileName.ToString(), solutionFileName);
            this.buildProject.SetGlobalProperty(GlobalProperty.SolutionName.ToString(), solutionName);
            this.buildProject.SetGlobalProperty(GlobalProperty.SolutionExt.ToString(), solutionExtension);

            // Other misc properties
            this.buildProject.SetGlobalProperty(GlobalProperty.BuildingInsideVisualStudio.ToString(), "true");
            this.buildProject.SetGlobalProperty(GlobalProperty.Configuration.ToString(), ProjectConfig.Debug);
            this.buildProject.SetGlobalProperty(GlobalProperty.Platform.ToString(), ProjectConfig.AnyCPU);

            // DevEnvDir property
            object installDirAsObject = null;

            if(this.Site.GetService(typeof(SVsShell)) is IVsShell shell)
            {
                // We do not want to throw. If we cannot set the solution related constants we set them to empty string.
                shell.GetProperty((int)__VSSPROPID.VSSPROPID_InstallDirectory, out installDirAsObject);
            }

            string installDir = ((string)installDirAsObject);

            if (String.IsNullOrEmpty(installDir))
            {
                installDir = String.Empty;
            }
            else
            {
                // Ensure that we have a trailing backslash as this is done for the langproj macros too.
                if (installDir[installDir.Length - 1] != Path.DirectorySeparatorChar)
                {
                    installDir += Path.DirectorySeparatorChar;
                }
            }

            this.buildProject.SetGlobalProperty(GlobalProperty.DevEnvDir.ToString(), installDir);
        }
    

开发者ID:EWSoftware,项目名称:SHFB,代码行数:73,代码来源:ProjectNode.cs

在SetupProjectGlobalPropertiesThatAllProjectSystemsMustSet()方法中,Path的代码示例类中的HasExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.HasExtension的代码示例5 - UpdateSelectedHistoryItem()

    using System.IO;

        public HistoryItem UpdateSelectedHistoryItem()
        {
            HistoryItem[] historyItems = OnGetHistoryItems();

            if (historyItems != null && historyItems.Length > 0)
            {
                HistoryItem = historyItems[0];
            }
            else
            {
                HistoryItem = null;
            }

            if (HistoryItem != null)
            {
                IsURLExist = !string.IsNullOrEmpty(HistoryItem.URL);
                IsShortenedURLExist = !string.IsNullOrEmpty(HistoryItem.ShortenedURL);
                IsThumbnailURLExist = !string.IsNullOrEmpty(HistoryItem.ThumbnailURL);
                IsDeletionURLExist = !string.IsNullOrEmpty(HistoryItem.DeletionURL);
                IsImageURL = IsURLExist && FileHelpers.IsImageFile(HistoryItem.URL);
                IsTextURL = IsURLExist && FileHelpers.IsTextFile(HistoryItem.URL);
                IsFilePathValid = !string.IsNullOrEmpty(HistoryItem.FilePath) && Path.HasExtension(HistoryItem.FilePath);
                IsFileExist = IsFilePathValid && File.Exists(HistoryItem.FilePath);
                IsImageFile = IsFileExist && FileHelpers.IsImageFile(HistoryItem.FilePath);
                IsTextFile = IsFileExist && FileHelpers.IsTextFile(HistoryItem.FilePath);

                UpdateContextMenu(historyItems.Length);
            }
            else
            {
                cmsHistory.Enabled = false;
            }

            return HistoryItem;
        }
    

开发者ID:ShareX,项目名称:ShareX,代码行数:37,代码来源:HistoryItemManager.cs

在UpdateSelectedHistoryItem()方法中,Path的代码示例类中的HasExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.HasExtension的代码示例6 - Update()

    using System.IO;

        public void Update()
        {
            if (Info.Result != null)
            {
                IsURLExist = !string.IsNullOrEmpty(Info.Result.URL);
                IsShortenedURLExist = !string.IsNullOrEmpty(Info.Result.ShortenedURL);
                IsThumbnailURLExist = !string.IsNullOrEmpty(Info.Result.ThumbnailURL);
                IsDeletionURLExist = !string.IsNullOrEmpty(Info.Result.DeletionURL);
                IsFileURL = IsURLExist && URLHelpers.IsFileURL(Info.Result.URL);
                IsImageURL = IsFileURL && FileHelpers.IsImageFile(Info.Result.URL);
                IsTextURL = IsFileURL && FileHelpers.IsTextFile(Info.Result.URL);
            }

            IsFilePathValid = !string.IsNullOrEmpty(Info.FilePath) && Path.HasExtension(Info.FilePath);
            IsFileExist = IsFilePathValid && File.Exists(Info.FilePath);
            IsThumbnailFilePathValid = !string.IsNullOrEmpty(Info.ThumbnailFilePath) && Path.HasExtension(Info.ThumbnailFilePath);
            IsThumbnailFileExist = IsThumbnailFilePathValid && File.Exists(Info.ThumbnailFilePath);
            IsImageFile = IsFileExist && FileHelpers.IsImageFile(Info.FilePath);
            IsTextFile = IsFileExist && FileHelpers.IsTextFile(Info.FilePath);
        }
    

开发者ID:ShareX,项目名称:ShareX,代码行数:22,代码来源:UploadInfoStatus.cs

在Update()方法中,Path的代码示例类中的HasExtension的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

本文中的Path.HasExtension方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。