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


C# OpenedFile.OpenRead方法代码示例

本文整理汇总了C#中ICSharpCode.SharpDevelop.OpenedFile.OpenRead方法的典型用法代码示例。如果您正苦于以下问题:C# OpenedFile.OpenRead方法的具体用法?C# OpenedFile.OpenRead怎么用?C# OpenedFile.OpenRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.SharpDevelop.OpenedFile的用法示例。


在下文中一共展示了OpenedFile.OpenRead方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateContentForFile

		public IViewContent CreateContentForFile(OpenedFile file)
		{
			var codons = DisplayBindingService.GetCodonsPerFileName(file.FileName);
			DisplayBindingDescriptor bestMatch = null;
			double max = double.NegativeInfinity;
			const int BUFFER_LENGTH = 4 * 1024;
			
			using (var stream = file.OpenRead()) {
				string mime = "text/plain";
				if (stream.Length > 0) {
					stream.Position = 0;
					mime = MimeTypeDetection.FindMimeType(new BinaryReader(stream).ReadBytes(BUFFER_LENGTH));
				}
				foreach (var codon in codons) {
					stream.Position = 0;
					double value = codon.Binding.AutoDetectFileContent(file.FileName, stream, mime);
					if (value > max) {
						max = value;
						bestMatch = codon;
					}
				}
			}
			
			if (bestMatch == null)
				throw new InvalidOperationException();
			
			return bestMatch.Binding.CreateContentForFile(file);
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:28,代码来源:AutoDetectDisplayBinding.cs

示例2: CreateContentForFile

		public IViewContent CreateContentForFile(OpenedFile file)
		{
			ChooseEncodingDialog dlg = new ChooseEncodingDialog();
			dlg.Owner = WorkbenchSingleton.MainWindow;
			using (Stream stream = file.OpenRead()) {
				using (StreamReader reader = FileReader.OpenStream(stream, FileService.DefaultFileEncoding.GetEncoding())) {
					reader.Peek(); // force reader to auto-detect encoding
					dlg.Encoding = reader.CurrentEncoding;
				}
			}
			if (dlg.ShowDialog() == true) {
				return new AvalonEditViewContent(file, dlg.Encoding);
			} else {
				return null;
			}
		}
开发者ID:nylen,项目名称:SharpDevelop,代码行数:16,代码来源:AvalonEditDisplayBinding.cs

示例3: OpenFileContentAsMemoryStream

			static MemoryStream OpenFileContentAsMemoryStream(OpenedFile file)
			{
				Stream stream = file.OpenRead();
				MemoryStream ms = stream as MemoryStream;
				if (ms == null) {
					// copy stream content to memory
					try {
						ms = new MemoryStream();
						byte[] buffer = new byte[4096];
						int c;
						do {
							c = stream.Read(buffer, 0, buffer.Length);
							ms.Write(buffer, 0, c);
						} while (c > 0);
						ms.Position = 0;
					} finally {
						stream.Dispose();
					}
				}
				return ms;
			}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:21,代码来源:ResourceStore.cs


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