本文整理汇总了C#中CSharpParser.Freeze方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpParser.Freeze方法的具体用法?C# CSharpParser.Freeze怎么用?C# CSharpParser.Freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpParser
的用法示例。
在下文中一共展示了CSharpParser.Freeze方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProvider
static CompletionDataList CreateProvider (string text, bool isCtrlSpace)
{
string parsedText;
string editorText;
int cursorPosition = text.IndexOf ('$');
int endPos = text.IndexOf ('$', cursorPosition + 1);
if (endPos == -1) {
parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1);
} else {
parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1);
editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1);
cursorPosition = endPos - 1;
}
var doc = new ReadOnlyDocument (editorText);
IProjectContent pctx = new CSharpProjectContent ();
pctx = pctx.AddAssemblyReferences (new [] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
var compilationUnit = new CSharpParser ().Parse (parsedText, "program.cs");
compilationUnit.Freeze ();
var parsedFile = compilationUnit.ToTypeSystem ();
pctx = pctx.UpdateProjectContent (null, parsedFile);
var cmp = pctx.CreateCompilation ();
var loc = doc.GetLocation (cursorPosition);
var rctx = new CSharpTypeResolveContext (cmp.MainAssembly);
rctx = rctx.WithUsingScope (parsedFile.GetUsingScope (loc).Resolve (cmp));
var curDef = parsedFile.GetInnermostTypeDefinition (loc);
if (curDef != null) {
var resolvedDef = curDef.Resolve (rctx).GetDefinition ();
rctx = rctx.WithCurrentTypeDefinition (resolvedDef);
var curMember = resolvedDef.Members.FirstOrDefault (m => m.Region.Begin <= loc && loc < m.BodyRegion.End);
if (curMember != null)
rctx = rctx.WithCurrentMember (curMember);
}
var engine = new CSharpCompletionEngine (doc, new TestFactory (), pctx, rctx, compilationUnit, parsedFile);
engine.EolMarker = Environment.NewLine;
engine.FormattingPolicy = FormattingOptionsFactory.CreateMono ();
var data = engine.GetCompletionData (cursorPosition, isCtrlSpace);
return new CompletionDataList () {
Data = data,
AutoCompleteEmptyMatch = engine.AutoCompleteEmptyMatch,
AutoSelect = engine.AutoSelect,
DefaultCompletionString = engine.DefaultCompletionString
};
}
示例2: CreateProvider
internal static IParameterDataProvider CreateProvider(string text)
{
string parsedText;
string editorText;
int cursorPosition = text.IndexOf('$');
int endPos = text.IndexOf('$', cursorPosition + 1);
if (endPos == -1) {
parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1);
} else {
parsedText = text.Substring(0, cursorPosition) + new string(' ', endPos - cursorPosition) + text.Substring(endPos + 1);
editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1);
cursorPosition = endPos - 1;
}
var doc = new ReadOnlyDocument(editorText);
IProjectContent pctx = new CSharpProjectContent();
pctx = pctx.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
var syntaxTree = new CSharpParser().Parse(parsedText, "program.cs");
syntaxTree.Freeze();
var unresolvedFile = syntaxTree.ToTypeSystem();
pctx = pctx.AddOrUpdateFiles(unresolvedFile);
var cmp = pctx.CreateCompilation();
var loc = doc.GetLocation(cursorPosition);
var rctx = new CSharpTypeResolveContext(cmp.MainAssembly);
rctx = rctx.WithUsingScope(unresolvedFile.GetUsingScope(loc).Resolve(cmp));
var curDef = unresolvedFile.GetInnermostTypeDefinition(loc);
if (curDef != null) {
rctx = rctx.WithCurrentTypeDefinition(curDef.Resolve(rctx).GetDefinition());
var curMember = unresolvedFile.GetMember(loc);
if (curMember != null) {
rctx = rctx.WithCurrentMember(curMember.CreateResolved(rctx));
}
}
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
var engine = new CSharpParameterCompletionEngine (doc, mb, new TestFactory (pctx), pctx, rctx);
return engine.GetParameterDataProvider (cursorPosition, doc.GetCharAt (cursorPosition - 1));
}
示例3: CreateCompilation
public static void CreateCompilation (string parsedText, out IProjectContent pctx, out SyntaxTree syntaxTree, out CSharpUnresolvedFile unresolvedFile, bool expectErrors, params IUnresolvedAssembly[] references)
{
pctx = new CSharpProjectContent();
var refs = new List<IUnresolvedAssembly> { mscorlib.Value, systemCore.Value, systemAssembly.Value, systemXmlLinq.Value };
if (references != null)
refs.AddRange (references);
pctx = pctx.AddAssemblyReferences(refs);
syntaxTree = new CSharpParser().Parse(parsedText, "program.cs");
syntaxTree.Freeze();
if (!expectErrors && syntaxTree.Errors.Count > 0) {
Console.WriteLine ("----");
Console.WriteLine (parsedText);
Console.WriteLine ("----");
foreach (var error in syntaxTree.Errors)
Console.WriteLine (error.Message);
Assert.Fail ("Parse error.");
}
unresolvedFile = syntaxTree.ToTypeSystem();
pctx = pctx.AddOrUpdateFiles(unresolvedFile);
}
示例4: CreateEngine
public static CSharpCompletionEngine CreateEngine(string text, out int cursorPosition, params IUnresolvedAssembly[] references)
{
string parsedText;
string editorText;
cursorPosition = text.IndexOf('$');
int endPos = text.IndexOf('$', cursorPosition + 1);
if (endPos == -1) {
if (cursorPosition < 0) {
parsedText = editorText = text;
} else {
parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1);
}
} else {
parsedText = text.Substring(0, cursorPosition) + new string(' ', endPos - cursorPosition) + text.Substring(endPos + 1);
editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1);
cursorPosition = endPos - 1;
}
var doc = new ReadOnlyDocument(editorText);
IProjectContent pctx = new CSharpProjectContent();
var refs = new List<IUnresolvedAssembly> { mscorlib.Value, systemCore.Value, systemAssembly.Value, systemXmlLinq.Value };
if (references != null)
refs.AddRange (references);
pctx = pctx.AddAssemblyReferences(refs);
var syntaxTree = new CSharpParser().Parse(parsedText, "program.cs");
syntaxTree.Freeze();
var unresolvedFile = syntaxTree.ToTypeSystem();
pctx = pctx.AddOrUpdateFiles(unresolvedFile);
var cmp = pctx.CreateCompilation();
var loc = cursorPosition > 0 ? doc.GetLocation(cursorPosition) : new TextLocation (1, 1);
var rctx = new CSharpTypeResolveContext(cmp.MainAssembly);
rctx = rctx.WithUsingScope(unresolvedFile.GetUsingScope(loc).Resolve(cmp));
var curDef = unresolvedFile.GetInnermostTypeDefinition(loc);
if (curDef != null) {
var resolvedDef = curDef.Resolve(rctx).GetDefinition();
rctx = rctx.WithCurrentTypeDefinition(resolvedDef);
var curMember = resolvedDef.Members.FirstOrDefault(m => m.Region.Begin <= loc && loc < m.BodyRegion.End);
if (curMember != null) {
rctx = rctx.WithCurrentMember(curMember);
}
}
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
mb.AddSymbol ("TEST");
var engine = new CSharpCompletionEngine(doc, mb, new TestFactory(new CSharpResolver (rctx)), pctx, rctx);
engine.EolMarker = Environment.NewLine;
engine.FormattingPolicy = FormattingOptionsFactory.CreateMono();
return engine;
}