本文整理汇总了C#中ITextSource.CreateReader方法的典型用法代码示例。如果您正苦于以下问题:C# ITextSource.CreateReader方法的具体用法?C# ITextSource.CreateReader怎么用?C# ITextSource.CreateReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextSource
的用法示例。
在下文中一共展示了ITextSource.CreateReader方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindAllValidating
public IEnumerable<ISearchResult> FindAllValidating(ITextSource document, int offset, int length)
{
using (var stream = document.CreateReader())
{
var doc = (IDocument)document;
var xmlDoc = new XPathDocument(stream); ;
var navigator = xmlDoc.CreateNavigator();
XPathExpression expr = null;
XPathNodeIterator iterator;
try
{
expr = navigator.Compile(_xPath);
iterator = navigator.Select(expr);
}
catch (System.Xml.XPath.XPathException)
{
yield break;
}
while (iterator.MoveNext())
{
var current = iterator.Current;
var segment = XmlSegment(doc, ((IXmlLineInfo)current).LineNumber, ((IXmlLineInfo)current).LinePosition);
if (segment != null && segment.Offset >= offset && segment.EndOffset <= (offset + length))
{
yield return new XPathSearchResult()
{
StartOffset = segment.Offset,
Length = segment.Length
};
}
}
}
}
示例2: GetFolds
public IList<FoldingRegion> GetFolds(ITextSource textSource)
{
try {
GetFolds(textSource.CreateReader());
return folds;
} catch (XmlException) {
}
return null;
}
示例3: Parse
public void Parse(IProject project, string fileName, string source)
{
this.FileName = fileName;
this.Content = new StringTextSource(source);
this.Document = new StringBuilderDocument(this.Content);
this.Project = project;
CSharpParser p = project.CreateParser();
this.SyntaxTree = p.Parse(Content.CreateReader(), fileName);
this.ParsedFile = this.SyntaxTree.ToTypeSystem();
}
示例4: Parse
private void Parse(IProject project, string fileName, string source)
{
Console.WriteLine("Loading " + fileName);
this.FileName = fileName;
this.Content = new StringTextSource(source);
this.Document = new StringBuilderDocument(this.Content);
this.Project = project;
CSharpParser p = project.CreateParser();
this.SyntaxTree = p.Parse(Content.CreateReader(), fileName);
this.ParsedFile = this.SyntaxTree.ToTypeSystem();
if(this.Project.ProjectContent != null)
this.Project.ProjectContent.AddOrUpdateFiles(this.ParsedFile);
}
示例5: Parse
private void Parse(IProject project, string fileName, string source)
{
Console.WriteLine("Loading " + fileName);
this.FileName = fileName;
this.Content = new StringTextSource(source);
this.Document = new ReadOnlyDocument(this.Content);
this.Project = project;
CSharpParser p = project.CreateParser();
this.SyntaxTree = p.Parse(Content.CreateReader(), fileName);
if (p.HasErrors)
{
Console.WriteLine("Error parsing " + fileName + ":");
foreach (var error in p.Errors)
{
Console.WriteLine(" " + error.Region + " " + error.Message);
}
}
this.ParsedFile = this.SyntaxTree.ToTypeSystem();
}
示例6: Parse
public CompilationUnit Parse (ITextSource textSource, string fileName, int lineModifier = 0)
{
return Parse (textSource.CreateReader (), fileName, lineModifier);
}
示例7: CSharpFile
public CSharpFile(CSharpProject project, string fileName)
{
this.Project = project;
this.FileName = fileName;
this.Content = new StringTextSource(File.ReadAllText(FileName));
this.LinesOfCode = 1 + this.Content.Text.Count(c => c == '\n');
CSharpParser p = new CSharpParser(project.CompilerSettings);
this.CompilationUnit = p.Parse(Content.CreateReader(), fileName);
if (p.HasErrors) {
Console.WriteLine("Error parsing " + fileName + ":");
foreach (var error in p.ErrorsAndWarnings) {
Console.WriteLine(" " + error.Region + " " + error.Message);
}
}
this.ParsedFile = this.CompilationUnit.ToTypeSystem();
}
示例8: FindAllForwardOnly
public IEnumerable<ISearchResult> FindAllForwardOnly(ITextSource document, int offset, int length)
{
var xc = new XPathCollection();
try
{
xc.Add(_xPath);
}
catch (Exception)
{
yield break;
}
using (var reader = new XmlTextReader(document.CreateReader()))
using (var xpathReader = new XPathReader(reader, xc))
{
var lineInfo = xpathReader as IXmlLineInfo;
var doc = (IDocument)document;
ISegment segment;
while (Read(xpathReader))
{
if (xpathReader.Match(0) && xpathReader.NodeType != XmlNodeType.EndElement)
{
segment = null;
try
{
segment = XmlSegment(doc, lineInfo.LineNumber, lineInfo.LinePosition);
}
catch (Exception) { }
if (segment != null && segment.Offset >= offset && segment.EndOffset <= (offset + length))
{
yield return new XPathSearchResult()
{
StartOffset = segment.Offset,
Length = segment.Length
};
}
}
}
}
}
示例9: ParseTemplate
ParserResults ParseTemplate(ITextSource textBuffer)
{
var host = new RazorEngineHost(new CSharpRazorCodeLanguage());
var engine = new RazorTemplateEngine(host);
return engine.ParseTemplate(textBuffer.CreateReader());
}
示例10: WriteTextSource
private async Task WriteTextSource(Stream stream, ITextSource data)
{
using (var writer = new StreamWriter(stream))
using (var reader = data.CreateReader())
{
await reader.CopyToAsync(writer);
}
}
示例11: ProcessFragment
//.........这里部分代码省略.........
else if (i + 8 < fragment.TextLength
&& fragment.GetCharAt(i + 1) == '!'
&& fragment.GetCharAt(i + 2) == '['
&& fragment.GetCharAt(i + 3) == 'C'
&& fragment.GetCharAt(i + 4) == 'D'
&& fragment.GetCharAt(i + 5) == 'A'
&& fragment.GetCharAt(i + 6) == 'T'
&& fragment.GetCharAt(i + 7) == 'A'
&& fragment.GetCharAt(i + 8) == '[')
{
i += 8;
state = XmlState.CData;
}
else
{
state = XmlState.Tag;
lastTag = new KeyValuePair<int, int>(line, i - lineOffsets.Last() + 2);
}
}
break;
}
break;
}
}
const string __noName = "___NO_NAME___";
const string __eof = "{`EOF`}";
var suffix = string.Empty;
switch (state)
{
case XmlState.Attribute:
if (char.IsWhiteSpace(fragment.GetCharAt(fragment.TextLength - 1)))
{
state = XmlState.AttributeStart;
suffix += ">";
}
else
{
suffix += "=\"\">";
}
break;
case XmlState.AttributeValue:
if (fragment.GetCharAt(fragment.TextLength - 1) == '=')
{
suffix += "''>";
}
else
{
suffix += attrValueQuote.ToString() + ">";
}
break;
case XmlState.CData:
suffix += "]]>";
break;
case XmlState.Comment:
suffix += "-->";
break;
case XmlState.Tag:
if (fragment.GetCharAt(fragment.TextLength - 1) == '<') suffix += __noName;
suffix += ">";
break;
}
suffix += "<!--" + __eof + "-->";
var settings = new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Fragment };
var textReader = new AugmentedReader(fragment.CreateReader(), suffix);
var reader = XmlReader.Create(textReader, settings);
var lineInfo = reader as IXmlLineInfo;
try
{
bool keepGoing = true;
while (keepGoing && reader.Read() && !(reader.NodeType == XmlNodeType.Comment && reader.Value == __eof))
{
if (reader.LocalName != __noName)
{
keepGoing = processor.Invoke(reader, lineOffsets[lineInfo.LineNumber - 1]
+ lineInfo.LinePosition
- (reader.NodeType == XmlNodeType.Element ? 2 : 1), state);
if (reader.NodeType == XmlNodeType.Element
&& lineInfo.LineNumber == lastTag.Key
&& lineInfo.LinePosition == lastTag.Value)
{
for (var i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i);
keepGoing = processor.Invoke(reader, lineOffsets[lineInfo.LineNumber - 1] + lineInfo.LinePosition - 1, state);
}
}
}
}
}
catch (XmlException)
{
// Do Nothing
}
return state;
}