예제 #1
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            FileDesc otherFileDesc = obj as FileDesc;

            if ((int)otherFileDesc.Size.Units == (int)this.Size.Units)
            {
                if (otherFileDesc.Size.Value > this.Size.Value)
                {
                    return(1);
                }
                else if (otherFileDesc.Size.Value < this.Size.Value)
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            }
            else if ((int)otherFileDesc.Size.Units > (int)this.Size.Units)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            string text = @"Text:file.txt(6B);Some string content
Image:img.bmp(19MB);1920x1080
Text:data.txt(12B);Another string
Text:data1.txt(7B);Yet another string
Movie:logan.2017.mkv(19GB);1920x1080; 2h12m";

            string[] strsFile = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            ParseStrFile[] strFiles = new ParseStrFile[strsFile.Length];
            FileDesc[]     files    = new FileDesc[strsFile.Length];

            for (int i = 0; i < strsFile.Length; i++)
            {
                strFiles[i] = new ParseStrFile(strsFile[i]);
                if (strFiles[i].Type == FileType.Text)
                {
                    files[i] = new TextFileDesc(strFiles[i].Name, strFiles[i].Type, strFiles[i].Extension, strFiles[i].Size, (string)strFiles[i].FileProp[0]);
                }
                if (strFiles[i].Type == FileType.Image)
                {
                    files[i] = new ImageFileDesc(strFiles[i].Name, strFiles[i].Type, strFiles[i].Extension, strFiles[i].Size, (string)strFiles[i].FileProp[0]);
                }
                if (strFiles[i].Type == FileType.Movie)
                {
                    files[i] = new MovieFileDesc(strFiles[i].Name, strFiles[i].Type, strFiles[i].Extension, strFiles[i].Size, (string)strFiles[i].FileProp[0], (string)strFiles[i].FileProp[1]);
                }
            }

            //TextFileDesc[] txtFiles =

            foreach (var file in files)
            {
                file.ShowDesc();
            }


            Console.ReadLine();
        }