本文整理汇总了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);
}
示例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;
}
}
示例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;
}