当前位置: 首页>>代码示例>>C#>>正文


C# System.IO类代码示例

本文整理汇总了C#中System.IO的典型用法代码示例。如果您正苦于以下问题:C# IO类的具体用法?C# IO怎么用?C# IO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IO类属于System命名空间,在下文中一共展示了IO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Notify

        public void Notify(object sender, IO.FileSystemEventArgs args)
        {
            char separator       = IO.Path.DirectorySeparatorChar;
            string relative_path = args.FullPath.Substring (Path.Length);
            relative_path        = relative_path.Trim (new char [] {' ', separator});

            // Ignore changes that happened in the parent path
            if (!relative_path.Contains (separator.ToString ()))
                return;

            string repo_name = relative_path.Substring (0, relative_path.IndexOf (separator));

            foreach (SparkleRepoBase repo in ReposToNotify) {
                if (repo.Name.Equals (repo_name) && !repo.IsBuffering &&
                    (repo.Status != SyncStatus.SyncUp && repo.Status != SyncStatus.SyncDown)) {

                    Thread thread = new Thread (
                        new ThreadStart (delegate {
                            repo.OnFileActivity (args);
                        })
                    );

                    thread.Start ();
                }
            }
        }
开发者ID:blakeeb,项目名称:SparkleShare,代码行数:26,代码来源:SparkleWatcher.cs

示例2: ReadShape

        public override ShapeBase ReadShape(IO.TextReader TReader)
        {
            var Reader = new IO.TextReaderWE(TReader);
            var Shapes = new ShapeCollection() { Name = "Parts" };

            var Lines = new List<Line>();

            while (!Reader.IsFinished)
            {
                Line L;
                PointF P1, P2;

                if (Reader.ReadLine().Trim() != "zone")
                {
                    throw new Exception("Invalid output");
                }

                var t = new String[] { " " };
                var PS = Reader.ReadLine().Split(t, StringSplitOptions.RemoveEmptyEntries);
                P1 = new PointF(Single.Parse(PS[0]), Single.Parse(PS[1]));
                PS = Reader.ReadLine().Split(t, StringSplitOptions.RemoveEmptyEntries);
                P2 = new PointF(Single.Parse(PS[0]), Single.Parse(PS[1]));
                L = new Line(P1, P2);
                Lines.Add(L);
            }

            Shapes.Shapes.Add(new LinesShape(Lines) { Name = "Part 1" });

            return Shapes;
        }
开发者ID:Shayan-To,项目名称:OpenMesh,代码行数:30,代码来源:Copy+of+Type1ShapeFileFormat.cs

示例3: EnumerateFiles

        public IEnumerable<string> EnumerateFiles(string directoryPath, string searchPattern, IO.SearchOption searchOption)
        {
            if (directoryPath == null)
                throw new ArgumentNullException("directoryPath");
            if (searchPattern == null)
                throw new ArgumentNullException("searchPattern");
            if (HaveFile(directoryPath))
                throw new IO.IOException("ファイル名は指定できません");
            if (searchPattern.Contains(IO.Path.AltDirectorySeparatorChar) || searchPattern.Contains(IO.Path.DirectorySeparatorChar))
                throw new ArgumentException("searchPattern");

            string lowerDirectoryPath = directoryPath.ToLower();
            var regex = new System.Text.RegularExpressions.Regex(searchPattern.TrimEnd(TrimEndChars).Replace("?", @".").Replace("*", @".*") + "$");

            switch (searchOption)
            {
                case System.IO.SearchOption.AllDirectories:
                    return InternalHeader.Keys
                        .Where(key => key.StartsWith(lowerDirectoryPath))
                        .Where(key => regex.IsMatch(IO.Path.GetFileName(key)));
                case System.IO.SearchOption.TopDirectoryOnly:
                    return InternalHeader.Keys
                        .Where(key => key.StartsWith(lowerDirectoryPath))
                        .Where(key => !key.Substring(lowerDirectoryPath.Length).Contains(IO.Path.PathSeparator))
                        .Where(key => regex.IsMatch(IO.Path.GetFileName(key)));
                default:
                    throw new ArgumentException("searchOption");
            }
        }
开发者ID:Pctg-x8,项目名称:Altseed,代码行数:29,代码来源:PackFile.cs

示例4: Dispose

 public static void Dispose(IO::FileStream aThis, bool disposing,
     [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream)
 {
     if (disposing)
     {
         innerStream.Dispose();
     }
 }
开发者ID:nstone101,项目名称:Cosmos,代码行数:8,代码来源:FileStreamImpl.cs

示例5: StreamWriter

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="stream">The stream </param>
        public StreamWriter(IO.Stream stream)
        {
            if (stream == null)
                throw new ArgumentNullException("stream", "The given stream must not be null.");
            if (!stream.CanWrite)
                throw new ArgumentException("The given stream must be writable.", "stream");

            this.stream = new IO.StreamWriter(stream);
        }
开发者ID:dineshkummarc,项目名称:easylog,代码行数:13,代码来源:StreamWriter.cs

示例6: EnumerateFileSystemEntries

 private static IEnumerable<string> EnumerateFileSystemEntries(string path, IO::SearchOption option, CancellationToken token, IProgress<double> iprogress, bool isEnumFiles, bool isEnumDirs, double progress, double step)
 {
     if(iprogress != null) {
         iprogress.Report(progress);
     }
     if(isEnumFiles){
         IEnumerable<string> files = null;
         try{
             files = IO::Directory.EnumerateFiles(path);
         }catch(IO::IOException){
         }catch(UnauthorizedAccessException){
         }
         if(files != null){
             foreach(var file in files) {
                 yield return file;
             }
         }
     }
     if(option == IO::SearchOption.AllDirectories){
         string[] dirs = null;
         try{
             dirs = IO::Directory.EnumerateDirectories(path).ToArray();
         }catch(IO::IOException){
         }catch(UnauthorizedAccessException){
         }
         if(dirs != null){
             if(isEnumDirs){
                 foreach(var dir in dirs) {
                     yield return dir;
                 }
             }
             var stepE = step / dirs.Length;
             for(int i = 0; i < dirs.Length; i++){
                 var prog = progress + (step * i * stepE);
                 foreach(var subfiles in EnumerateFileSystemEntries(dirs[i], option, token, iprogress, isEnumFiles, isEnumDirs, prog, stepE)){
                     yield return subfiles;
                 }
             }
         }
     }else if(isEnumDirs){
         IEnumerable<string> dirsQ = null;
         try{
             dirsQ = IO::Directory.EnumerateDirectories(path);
         }catch(IO::IOException){
         }catch(UnauthorizedAccessException){
         }
         if(dirsQ != null){
             if(iprogress != null){
                 iprogress.Report(progress + step);
             }
             foreach(var dir in dirsQ) {
                 yield return dir;
             }
         }
     }
 }
开发者ID:catwalkagogo,项目名称:Heron,代码行数:56,代码来源:Seq.Directory.cs

示例7: GetFileMode

 private static FileMode GetFileMode(IO.FileMode mode)
 {
     if (mode != IO.FileMode.Append)
     {
         return (FileMode)(int)mode;
     }
     else
     {
         return (FileMode)(int)IO.FileMode.OpenOrCreate;
     }
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:11,代码来源:Kernel32File.cs

示例8: WriteShape

        public override void WriteShape(ShapeBase Shape, IO.TextWriter Writer)
        {
            var Dic = new Dictionary<PointF, Int32>();
            var Sz = 0;

            ShapeWalker.Instance.TypedWalk<LinesShape>(Shape, S => { Sz++; });
            Writer.WriteLine(Sz);
            ShapeWalker.Instance.TypedWalk<LinesShape>(Shape, S => { Writer.WriteLine(S.Lines.Count); });

            Sz = 0;
            ShapeWalker.Instance.TypedWalk<LinesShape>(Shape,
                S =>
                {
                    foreach (var L in S.Lines)
                    {
                        if (!Dic.ContainsKey(L.P1))
                        {
                            Dic.Add(L.P1, Sz++);
                        }
                        if (!Dic.ContainsKey(L.P2))
                        {
                            Dic.Add(L.P2, Sz++);
                        }
                    }
                });

            Writer.WriteLine(Sz);
            foreach (var KV in Dic.OrderBy(KV => KV.Value))
            {
                Writer.Write(KV.Key.X);
                Writer.Write(" ");
                Writer.Write(KV.Key.Y);
                Writer.WriteLine();
            }

            ShapeWalker.Instance.TypedWalk<LinesShape>(Shape,
                S =>
                {
                    Writer.WriteLine();
                    foreach (var l in S.Lines)
                    {
                        Writer.Write(Dic[l.P1]);
                        Writer.Write(" ");
                        Writer.Write(Dic[l.P2]);
                        Writer.WriteLine();
                    }
                });
        }
开发者ID:Shayan-To,项目名称:OpenMesh,代码行数:48,代码来源:Type1ShapeFileFormat.cs

示例9: Seek

			/// <summary>Seeks to the specified offset. Origin is always Current, Begin and End are ignored.</summary>
			/// <param name="offset">Offset to seek to</param>
			/// <param name="origin">Origin. Always System.IO.SeekOrigin.Current</param>
			/// <returns>New position, meaningless in a circularbuffer</returns>
			public override long Seek(long offset, IO.SeekOrigin origin)
			{
				lock (this.buffer)
				{
					if (this.buffer.readPosition + offset >= this.buffer.internalData.Length)
					{
						this.buffer.readPosition = (this.buffer.readPosition + offset) % this.buffer.internalData.Length;
					}
					else if (this.buffer.readPosition + offset < 0)
					{
						this.buffer.readPosition = this.buffer.internalData.Length + this.buffer.readPosition + offset;
					}
					else
						this.buffer.readPosition += offset;
					
					return this.buffer.readPosition;
				}
			}
开发者ID:peteward44,项目名称:torrent.net,代码行数:22,代码来源:circularbuffer.cs

示例10: Open

        internal static IO.FileStream Open(string path, IO.FileAccess access, IO.FileMode mode, IO.FileShare share = IO.FileShare.None, bool throwException = true)
        {
            var fileHandle = CreateFile(path, GetFileAccess(access), GetFileShare(share), default(IntPtr), GetFileMode(mode));

            if (fileHandle.IsInvalid)
            {
                if (throwException)
                {
                    HandleCOMError(Marshal.GetLastWin32Error());
                }
                else
                {
                    return null;
                }
            }

            return new IO.FileStream(fileHandle, access);
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:18,代码来源:Kernel32File.cs

示例11: WriteShape

        public override void WriteShape(ShapeBase Shape, IO.TextWriter Writer)
        {
            ShapeWalker.Instance.TypedWalk<LinesShape>(Shape,
                S =>
                {
                    foreach (var l in S.Lines)
                    {
                        Writer.WriteLine(" zone");

                        Writer.Write(l.P1.X);
                        Writer.Write(" ");
                        Writer.Write(l.P1.Y);
                        Writer.WriteLine();

                        Writer.Write(l.P2.X);
                        Writer.Write(" ");
                        Writer.Write(l.P2.Y);
                        Writer.WriteLine();
                    }
                });
        }
开发者ID:Shayan-To,项目名称:OpenMesh,代码行数:21,代码来源:Copy+of+Type1ShapeFileFormat.cs

示例12: ReadShape

        public override ShapeBase ReadShape(IO.TextReader Reader)
        {
            int n = int.Parse(Reader.ReadLine().Trim());
            var ar = new int[n];
            for (int i = 0; i < n; i++)
            {
                ar[i] = int.Parse(Reader.ReadLine().Trim());
            }
            int m = int.Parse(Reader.ReadLine().Trim());

            var Points = new PointF[m];

            for (int i = 0; i < m; i++)
            {
                var L = Reader.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                Points[i] = new PointF(Single.Parse(L[0]), Single.Parse(L[1]));
            }

            var Collection = new ShapeCollection() { Name = "Parts" };

            var MyColors = new Color[] { Color.Red, Color.Blue, Color.Magenta, Color.Green, Color.Teal };

            for (int i = 0; i < n; i++)
            {
                m = ar[i];
                var S = new List<Line>();

                for (int j = 0; j < m; j++)
                {
                    var L = Reader.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    S.Add(new Line(Points[int.Parse(L[0]) - 1], Points[int.Parse(L[1]) - 1]));
                }

                Collection.Shapes.Add(new LinesShape(S) { Color = MyColors[i], Name = "Part " + (i + 1).ToString() });
            }

            return Collection;
        }
开发者ID:Shayan-To,项目名称:OpenMesh,代码行数:38,代码来源:Type1ShapeFileFormat.cs

示例13: SetLength

 public static void SetLength(IO::FileStream aThis, long aLength,
     [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream)
 {
     innerStream.SetLength(aLength);
 }
开发者ID:nstone101,项目名称:Cosmos,代码行数:5,代码来源:FileStreamImpl.cs

示例14: get_Length

 public static long get_Length(IO::FileStream aThis,
     [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream)
 {
     return innerStream.Length;
 }
开发者ID:nstone101,项目名称:Cosmos,代码行数:5,代码来源:FileStreamImpl.cs

示例15: Write

 public static void Write(IO::FileStream aThis, byte[] aBuffer, int aOffset, int aCount,
     [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream)
 {
     innerStream.Write(aBuffer, aOffset, aCount);
 }
开发者ID:nstone101,项目名称:Cosmos,代码行数:5,代码来源:FileStreamImpl.cs


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