C# FileInfo.Equals的代码示例

通过代码示例来学习C# FileInfo.Equals方法

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


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

FileInfo.Equals的代码示例1 - CreateResilientPackage()

    using System.IO;

        static void CreateResilientPackage(Session session)
        {
            var productCode = session.Property("ProductCode");

            var userSID = session.Property("ALLUSERS") == "1" ? "S-1-5-18" : session.Property("UserSID");
            var localPackage = GetLocalPackageFromRegistry(productCode, userSID);

            session.Log($"LocalPackage:'{localPackage}'");

            var resilientLocation = session.Property(WIXSHARP_RESILIENT_SOURCE_DIR);
            var originalPackage = session.Property("OriginalDatabase");
            var packageName = IO.Path.GetFileName(originalPackage);
            if (string.IsNullOrEmpty(packageName))
            {
                throw new ArgumentNullException($"PackageName is null.");
            }
            var resilientPackage = IO.Path.Combine(resilientLocation, packageName);

            var resilientPackageInfo = new IO.FileInfo(resilientPackage);
            if (resilientPackageInfo.Exists && resilientPackage.Equals(originalPackage, StringComparison.OrdinalIgnoreCase) && !IsSymbolicLink(resilientPackageInfo))
            {
                return;
            }

            IO.File.Delete(resilientPackage);

            // NOTES: * CreateSymbolicLink() fails under Windows 7 in the elevated context (works with Windows 8 and above),
            //          so the execution falls back to the CreateHardLink().
            //
            //        * Non-elevated installers don't have access to the %WINDIR%\Installer, so the execution falls back to the file copying.
            //
            //        * One should be careful with trying to created a hard link to the "originalPackage", because when MSI is installed through
            //          the NSIS bootstrapper, the bootstrapper is extracting MSI in a temporary folder with very restrictive access rights.
            //          A hard link to the MSI has the same restrictive access rights preventing it from doing repairs through ARP applet.
            //
            //        * Hard links should not be created to the "localPackage" (e.g. %WINDIR%\Installer\xxxxxxx.msi), because during the uninstall
            //          the local package file and therefore the hard-linked file are both locked by MSI installer and cannot be removed.

            // Create a symbolic link
            var result = CreateSymbolicLink(resilientPackage, localPackage, SymbolicLinkFlag.File);
            if (!result)
            {
                var errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
                session.Log($"Failed to create a symbolic link. Link:'{resilientPackage}' Target:'{localPackage}' Error:{errorMessage}");
            }

            // Copy the file
            if (!result)
            {
                IO.File.Copy(originalPackage, resilientPackage, true);
            }
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:54,代码来源:ResilientPackage.cs

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

FileInfo.Equals的代码示例2 - LoadImageFromFile()

    using System.IO;

        /// 
        /// 
        /// 
        /// 
        /// 
        protected void LoadImageFromFile(string src, HtmlImageLoadEventArgs imageLoadEvent)
        {
            try
            {
                Uri uri = new Uri(src);
                //Try to load the file as Image from file
                //Remove the scheme first
                string srcWithoutScheme = src;
                int i = srcWithoutScheme.IndexOf(':');
                if (i > 0) srcWithoutScheme = srcWithoutScheme.Substring(i + 1).TrimStart('/');
                //If not absolute, add the current file path
                if (!Path.IsPathRooted(srcWithoutScheme))
                {
                    uri = new Uri(@"file:///" + this.FileInfo.FileDirectory + "/" + srcWithoutScheme);
                }

                //For SVG images: Convert to Bitmap
                string extension = Path.GetExtension(src);
                if (extension != null && extension.Equals(".svg", StringComparison.OrdinalIgnoreCase))
                {
                    ConvertSvgToBitmap(SvgDocument.Open(uri.LocalPath), imageLoadEvent);
                }
                else
                {
                    //Load uri, 8, 1
                    imageLoadEvent.Callback((Bitmap)Image.FromFile(uri.LocalPath, true));
                }
            }
            catch { } //Not able to handle, refer back to orginal process
        }
    

开发者ID:nea,项目名称:MarkdownViewerPlusPlus,代码行数:37,代码来源:MarkdownViewerRenderer.cs

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

FileInfo.Equals的代码示例3 - AddNonMemberItems()

    using System.IO;

        /// 
        /// Add non-member items to the hierarchy
        /// 
        private void AddNonMemberItems()
        {
            string path;

            var ignoredFolders = this.FoldersToIgnore();

            // Get a list of the folders and files in the project folder excluding those that are hidden or not
            // wanted.  Hash sets are used so that we can do case-insensitive comparisons when excluding existing
            // project items from the lists.
            HashSet folders = new HashSet(Directory.EnumerateDirectories(
                this.ProjectFolder, "*", SearchOption.AllDirectories).Where(p =>
                {
                    if(ignoredFolders.Any(folder => p.StartsWith(folder, StringComparison.OrdinalIgnoreCase)))
                        return false;

                    DirectoryInfo di = new DirectoryInfo(p);

                    return !((di.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden);
                }).Select(p => PackageUtilities.MakeRelative(this.ProjectFolder, p)),
                StringComparer.OrdinalIgnoreCase);

            HashSet files = new HashSet(Directory.EnumerateFiles(
                this.ProjectFolder, "*", SearchOption.AllDirectories).Where(f =>
                {
                    if(ignoredFolders.Any(folder => f.StartsWith(folder, StringComparison.OrdinalIgnoreCase)))
                        return false;

                    FileInfo fi = new FileInfo(f);

                    return !((fi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden);
                }).Select(f => PackageUtilities.MakeRelative(this.ProjectFolder, f)),
                StringComparer.OrdinalIgnoreCase);

            // Remove the folders and files that are already in the project
            foreach(Microsoft.Build.Evaluation.ProjectItem item in this.BuildProject.Items)
                if(folders.Count != 0 && item.ItemType.Equals(ProjectFileConstants.Folder,
                  StringComparison.OrdinalIgnoreCase))
                {
                    path = item.EvaluatedInclude;

                    // It should be relative already but check it just in case
                    if(Path.IsPathRooted(path)) 
                        path = PackageUtilities.MakeRelative(this.ProjectFolder, path);

                    if(folders.Contains(path))
                        folders.Remove(path);
                }
                else
                    if(files.Count != 0 && this.IsItemTypeFileType(item.ItemType))
                    {
                        path = item.EvaluatedInclude;

                        // It should be relative already but check it just in case
                        if(Path.IsPathRooted(path)) 
                            path = PackageUtilities.MakeRelative(this.ProjectFolder, path);

                        if(files.Contains(path))
                            files.Remove(path);
                    }

            // Add the remaining items to the project
            this.AddNonMemberFolderItems(folders);
            this.AddNonMemberFileItems(files);
        }
    

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

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

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