public WithCurrentUsingScope ( ResolvedUsingScope usingScope ) : CSharpResolver | ||
usingScope | ResolvedUsingScope | |
리턴 | CSharpResolver |
string ConvertHelper(AstNode node, Action<CSharpCodeProvider, CodeObject, TextWriter, CodeGeneratorOptions> action) { CSharpResolver resolver = new CSharpResolver(compilation); resolver = resolver.WithCurrentUsingScope(unresolvedFile.RootUsingScope.Resolve(compilation)); resolver = resolver.WithCurrentTypeDefinition(compilation.FindType(KnownTypeCode.Object).GetDefinition()); var codeObj = convertVisitor.Convert(node, new CSharpAstResolver(resolver, node)); StringWriter writer = new StringWriter(); writer.NewLine = " "; action(new CSharpCodeProvider(), codeObj, writer, new CodeGeneratorOptions { IndentString = " " }); return Regex.Replace(writer.ToString(), @"\s+", " ").Trim(); }
string Convert(Expression expr) { CSharpResolver resolver = new CSharpResolver(compilation); resolver = resolver.WithCurrentUsingScope(parsedFile.RootUsingScope.Resolve(compilation)); resolver = resolver.WithCurrentTypeDefinition(compilation.FindType(KnownTypeCode.Object).GetDefinition()); var codeExpr = (CodeExpression)convertVisitor.Convert(expr, new CSharpAstResolver(resolver, expr, parsedFile)); StringWriter writer = new StringWriter(); writer.NewLine = " "; new CSharpCodeProvider().GenerateCodeFromExpression(codeExpr, writer, new CodeGeneratorOptions { IndentString = " " }); return Regex.Replace(writer.ToString(), @"\s+", " "); }
public void SimpleNameLookupWithoutContext() { // without any using scope, we still want to find elements of the global namespace: var nrr = (NamespaceResolveResult)resolver.WithCurrentUsingScope(null).ResolveSimpleName("System", new IType[0]); Assert.AreEqual("System", nrr.NamespaceName); }
public void SimpleNameLookupWithoutContext() { // nothing should be found without specifying any UsingScope - however, the resolver also must not crash Assert.IsTrue(resolver.WithCurrentUsingScope(null).ResolveSimpleName("System", new IType[0]).IsError); }