using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SuperDesign.Tools.SmartEditor { public class MyFileSystemInfo : IEquatable { public MyFileSystemInfo(FileSystemInfo fileSystemInfo,string name) { if (fileSystemInfo == null) throw new ArgumentNullException("fileSystemInfo"); this.info = fileSystemInfo; if (name.Length == 0) { this.Name = info.Name; } else { this.Name = name; } } public bool IsDirectory { get { return this.AsDirectory != null; } } public DirectoryInfo AsDirectory { get { return this.info as DirectoryInfo; } } public FileInfo AsFile { get { return this.info as FileInfo; } } private readonly FileSystemInfo info; public string Name { get; set; } = ""; public string Extension { get { return this.info.Extension; } } public DateTime LastWriteTime { get { return this.info.LastWriteTime; } } public DateTime CreationTime { get { return this.info.CreationTime; } } public string FullName { get { return this.info.FullName; } } public FileAttributes Attributes { get { return this.info.Attributes; } } public long Length { get { return this.AsFile.Length; } } public IEnumerable GetFileSystemInfos() { ArrayList children = new ArrayList(); if (this.IsDirectory) { foreach(var x in this.AsDirectory.GetDirectories()) { children.Add(new MyFileSystemInfo(x, "")); } foreach (var x in this.AsDirectory.GetFiles()) { children.Add(new MyFileSystemInfo(x, "")); } } return children; } // Two file system objects are equal if they point to the same file system path public bool Equals(MyFileSystemInfo other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other.info.FullName, this.info.FullName); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (obj.GetType() != typeof(MyFileSystemInfo)) return false; return Equals((MyFileSystemInfo)obj); } public override int GetHashCode() { return (this.info != null ? this.info.FullName.GetHashCode() : 0); } public static bool operator ==(MyFileSystemInfo left, MyFileSystemInfo right) { return Equals(left, right); } public static bool operator !=(MyFileSystemInfo left, MyFileSystemInfo right) { return !Equals(left, right); } } }