C# StreamReader.Peek的代码示例
通过代码示例来学习C# StreamReader.Peek方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
StreamReader.Peek是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的StreamReader.Peek() 已经帮大家高亮显示了,大家可以重点学习StreamReader.Peek() 方法的写法,从而快速掌握该方法的应用。
StreamReader.Peek的代码示例1 - CreateInnerSourceDocument()
using System.IO; private static RazorSourceDocument CreateInnerSourceDocument(Stream stream, Encoding encoding, RazorSourceDocumentProperties properties) { var streamLength = (int)stream.Length; var content = string.Empty; var contentEncoding = encoding ?? Encoding.UTF8; if (streamLength > 0) { var bufferSize = Math.Min(streamLength, LargeObjectHeapLimitInChars); var reader = new StreamReader( stream, contentEncoding, detectEncodingFromByteOrderMarks: true, bufferSize: bufferSize, leaveOpen: true); using (reader) { reader.Peek(); // Just to populate the encoding if (encoding == null) { contentEncoding = reader.CurrentEncoding; } else if (encoding != reader.CurrentEncoding) { throw new InvalidOperationException( Resources.FormatMismatchedContentEncoding( encoding.EncodingName, reader.CurrentEncoding.EncodingName)); } if (streamLength > LargeObjectHeapLimitInChars) { // If the resulting string would end up on the large object heap, then use LargeTextSourceDocument. return new LargeTextSourceDocument( reader, LargeObjectHeapLimitInChars, contentEncoding, properties); } content = reader.ReadToEnd(); } } return new StringSourceDocument(content, contentEncoding, properties); }
开发者ID:aspnet,项目名称:Razor,代码行数:51,代码来源:StreamSourceDocument.cs
在CreateInnerSourceDocument()方法中,StreamReader的代码示例类中的Peek的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamReader.Peek的代码示例2 - ToTextAll()
using System.IO; public static string ToTextAll
(IEnumerable records, ChoXmlRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string xpath = null) where TRec : class { if (records == null) return null; if (typeof(DataTable).IsAssignableFrom(typeof(TRec))) { StringBuilder xml = new StringBuilder(); foreach (var dt in records.Take(1)) { using (var w = new ChoXmlWriter(xml, configuration)) w.Write(dt); } return xml.ToString(); } else if (typeof(IDataReader).IsAssignableFrom(typeof(TRec))) { StringBuilder xml = new StringBuilder(); foreach (var dt in records.Take(1)) { using (var w = new ChoXmlWriter(xml, configuration)) w.Write(dt); } return xml.ToString(); } var pe = new ChoPeekEnumerator (records, (Func )null); if (configuration == null) { configuration = new ChoXmlRecordConfiguration(); } configuration.IgnoreRootName = false; TRec record = pe.Peek; if (record != null) { if (configuration.NodeName.IsNullOrWhiteSpace()) { ChoDynamicObject rec1 = record as ChoDynamicObject; if (rec1 != null) { configuration.NodeName = rec1.DynamicObjectName; if (configuration.RootName.IsNullOrWhiteSpace()) configuration.RootName = configuration.NodeName.ToPlural(); } else { XmlRootAttribute root = ChoType.GetCustomAttribute (record.GetType(), false); string nodeName = "XElement"; if (root != null && !root.ElementName.IsNullOrWhiteSpace()) nodeName = root.ElementName.Trim(); else { var t = record.GetType().GetUnderlyingType().GetItemType(); nodeName = t.Name; } if (configuration.RootName.IsNullOrWhiteSpace()) configuration.RootName = nodeName.ToPlural(); configuration.NodeName = nodeName; } } } else { if (configuration.RootName.IsNullOrWhiteSpace()) configuration.RootName = "Root"; } using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoXmlWriter (writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch }) { //parser.Configuration.XPath = xpath; parser.Write(pe.ToEnumerable()); parser.Close(); writer.Flush(); stream.Position = 0; return reader.ReadToEnd(); } }
开发者ID:Cinchoo,项目名称:ChoETL,代码行数:95,代码来源:ChoXmlWriter.cs
在ToTextAll()方法中,StreamReader的代码示例类中的Peek的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamReader.Peek的代码示例3 - Load()
using System.IO; ///
/// Loads the HTML document from the specified TextReader. /// /// The TextReader used to feed the HTML data into the document. May not be null. public void Load(TextReader reader) { // all Load methods pass down to this one if (reader == null) throw new ArgumentNullException("reader"); _onlyDetectEncoding = false; if (OptionCheckSyntax) Openednodes = new Dictionary(); else Openednodes = null; if (OptionUseIdAttribute) { Nodesid = new Dictionary (StringComparer.OrdinalIgnoreCase); } else { Nodesid = null; } StreamReader sr = reader as StreamReader; if (sr != null) { try { // trigger bom read if needed sr.Peek(); } // ReSharper disable EmptyGeneralCatchClause catch (Exception) // ReSharper restore EmptyGeneralCatchClause { // void on purpose } _streamencoding = sr.CurrentEncoding; } else { _streamencoding = null; } _declaredencoding = null; Text = reader.ReadToEnd(); _documentnode = CreateNode(HtmlNodeType.Document, 0); Parse(); if (!OptionCheckSyntax || Openednodes == null) return; foreach (HtmlNode node in Openednodes.Values) { if (!node._starttag) // already reported { continue; } string html; if (OptionExtractErrorSourceText) { html = node.OuterHtml; if (html.Length > OptionExtractErrorSourceTextMaxLength) { html = html.Substring(0, OptionExtractErrorSourceTextMaxLength); } } else { html = string.Empty; } AddError( HtmlParseErrorCode.TagNotClosed, node._line, node._lineposition, node._streamposition, html, "End tag " + node.Name + "> was not found"); } // we don't need this anymore Openednodes.Clear(); }
开发者ID:zzzprojects,项目名称:html-agility-pack,代码行数:89,代码来源:HtmlDocument.cs
在Load()方法中,StreamReader的代码示例类中的Peek的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的StreamReader.Peek方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。