本文整理汇总了C#中CSharpUnresolvedFile类的典型用法代码示例。如果您正苦于以下问题:C# CSharpUnresolvedFile类的具体用法?C# CSharpUnresolvedFile怎么用?C# CSharpUnresolvedFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CSharpUnresolvedFile类属于命名空间,在下文中一共展示了CSharpUnresolvedFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateCompilationWithoutCorlib
public static ICompilation CreateCompilationWithoutCorlib(params IUnresolvedTypeDefinition[] unresolvedTypeDefinitions)
{
var unresolvedFile = new CSharpUnresolvedFile();
foreach (var typeDef in unresolvedTypeDefinitions)
unresolvedFile.TopLevelTypeDefinitions.Add(typeDef);
return CreateCompilation(unresolvedFile);
}
示例2: DelegateDataProvider
public DelegateDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType delegateType) : base (ext, startOffset)
{
compilation = ext.UnresolvedFileCompilation;
file = ext.CSharpUnresolvedFile;
// this.delegateType = delegateType;
this.delegateMethod = delegateType.GetDelegateInvokeMethod ();
}
示例3: Resolve
public static ResolveResult Resolve(Lazy<ICompilation> compilation, CSharpUnresolvedFile unresolvedFile, SyntaxTree syntaxTree, TextLocation location, out AstNode node,
CancellationToken cancellationToken = default(CancellationToken))
{
node = syntaxTree.GetNodeAt(location);
if (node == null || node is ArrayInitializerExpression)
return null;
if (node.Parent is UsingAliasDeclaration && node.Role == UsingAliasDeclaration.AliasRole) {
var r = new CSharpAstResolver(compilation.Value, syntaxTree, unresolvedFile);
return r.Resolve(((UsingAliasDeclaration)node.Parent).Import, cancellationToken);
}
if (CSharpAstResolver.IsUnresolvableNode(node)) {
if (node is Identifier) {
node = node.Parent;
} else if (node.NodeType == NodeType.Token) {
if (node.Parent is IndexerExpression || node.Parent is ConstructorInitializer) {
// There's no other place where one could hover to see the indexer's tooltip,
// so we need to resolve it when hovering over the '[' or ']'.
// For constructor initializer, the same applies to the 'base'/'this' token.
node = node.Parent;
} else {
return null;
}
} else {
// don't resolve arbitrary nodes - we don't want to show tooltips for everything
return null;
}
} else {
// It's a resolvable node.
// However, we usually don't want to show the tooltip everywhere
// For example, hovering with the mouse over an empty line between two methods causes
// node==TypeDeclaration, but we don't want to show any tooltip.
if (!node.GetChildByRole(Roles.Identifier).IsNull) {
// We'll suppress the tooltip for resolvable nodes if there is an identifier that
// could be hovered over instead:
return null;
}
}
if (node == null)
return null;
if (node.Parent is ObjectCreateExpression && node.Role == Roles.Type) {
node = node.Parent;
}
InvocationExpression parentInvocation = null;
if ((node is IdentifierExpression || node is MemberReferenceExpression || node is PointerReferenceExpression) && node.Role != Roles.Argument) {
// we also need to resolve the invocation
parentInvocation = node.Parent as InvocationExpression;
}
// TODO: I think we should provide an overload so that an existing CSharpAstResolver can be reused
CSharpAstResolver resolver = new CSharpAstResolver(compilation.Value, syntaxTree, unresolvedFile);
ResolveResult rr = resolver.Resolve(node, cancellationToken);
if (rr is MethodGroupResolveResult && parentInvocation != null)
return resolver.Resolve(parentInvocation);
else
return rr;
}
示例4: IndexerParameterDataProvider
public IndexerParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType type, IEnumerable<IProperty> indexers, AstNode resolvedExpression) : base (ext, startOffset)
{
compilation = ext.UnresolvedFileCompilation;
file = ext.CSharpUnresolvedFile;
// this.resolvedExpression = resolvedExpression;
this.indexers = new List<IProperty> (indexers);
}
示例5: Prepare
protected void Prepare(string source, bool minimizeNames = true, bool expectErrors = false) {
IProjectContent project = new CSharpProjectContent();
var parser = new CSharpParser();
using (var rdr = new StringReader(source)) {
var pf = new CSharpUnresolvedFile { FileName = "File.cs" };
var syntaxTree = parser.Parse(rdr, pf.FileName);
syntaxTree.AcceptVisitor(new TypeSystemConvertVisitor(pf));
project = project.AddOrUpdateFiles(pf);
}
project = project.AddAssemblyReferences(new[] { Files.Mscorlib });
_errorReporter = new MockErrorReporter(!expectErrors);
var compilation = project.CreateCompilation();
var s = new AttributeStore(compilation, _errorReporter);
RunAutomaticMetadataAttributeAppliers(s, compilation);
s.RunAttributeCode();
Metadata = new MetadataImporter(_errorReporter, compilation, s, new CompilerOptions { MinimizeScript = minimizeNames });
Metadata.Prepare(compilation.GetAllTypeDefinitions());
AllErrors = _errorReporter.AllMessages.ToList().AsReadOnly();
AllErrorTexts = _errorReporter.AllMessages.Select(m => m.FormattedMessage).ToList().AsReadOnly();
if (expectErrors) {
Assert.That(AllErrorTexts, Is.Not.Empty, "Compile should have generated errors");
}
else {
Assert.That(AllErrorTexts, Is.Empty, "Compile should not generate errors");
}
AllTypes = compilation.MainAssembly.TopLevelTypeDefinitions.SelectMany(SelfAndNested).ToDictionary(t => t.ReflectionName);
}
示例6: CSharpFullParseInformation
public CSharpFullParseInformation(CSharpUnresolvedFile unresolvedFile, ITextSourceVersion parsedVersion, SyntaxTree compilationUnit)
: base(unresolvedFile, parsedVersion, isFullParseInformation: true)
{
if (unresolvedFile == null)
throw new ArgumentNullException("unresolvedFile");
if (compilationUnit == null)
throw new ArgumentNullException("compilationUnit");
this.syntaxTree = compilationUnit;
}
示例7: DefaultCompletionContextProvider
public DefaultCompletionContextProvider (IDocument document, CSharpUnresolvedFile unresolvedFile)
{
if (document == null)
throw new ArgumentNullException("document");
if (unresolvedFile == null)
throw new ArgumentNullException("unresolvedFile");
this.document = document;
this.unresolvedFile = unresolvedFile;
}
示例8: CSharpAstResolver
/// <summary>
/// Creates a new C# AST resolver.
/// Use this overload if you are resolving within a complete C# file.
/// </summary>
/// <param name="compilation">The current compilation.</param>
/// <param name="syntaxTree">The syntax tree to be resolved.</param>
/// <param name="unresolvedFile">
/// Optional: Result of <see cref="SyntaxTree.ToTypeSystem()"/> for the file being resolved.
/// <para>
/// This is used for setting up the context on the resolver. The unresolved file must be registered in the compilation.
/// </para>
/// <para>
/// When a unresolvedFile is specified, the resolver will use the member's StartLocation/EndLocation to identify
/// member declarations in the AST with members in the type system.
/// When no unresolvedFile is specified (<c>null</c> value for this parameter), the resolver will instead compare the
/// member's signature in the AST with the signature in the type system.
/// </para>
/// </param>
public CSharpAstResolver(ICompilation compilation, SyntaxTree syntaxTree, CSharpUnresolvedFile unresolvedFile = null)
{
if (compilation == null)
throw new ArgumentNullException("compilation");
if (syntaxTree == null)
throw new ArgumentNullException("syntaxTree");
this.initialResolverState = new CSharpResolver(compilation);
this.rootNode = syntaxTree;
this.unresolvedFile = unresolvedFile;
this.resolveVisitor = new ResolveVisitor(initialResolverState, unresolvedFile);
}
示例9: CSharpFile
public CSharpFile(CSharpProject project, FileName fileName)
{
this.Project = project;
this.FileName = fileName;
this.OriginalText = File.ReadAllText(fileName);
CSharpParser p = new CSharpParser(project.CompilerSettings);
this.SyntaxTree = p.Parse(this.OriginalText, fileName);
this.UnresolvedTypeSystemForFile = SD.ParserService.GetExistingUnresolvedFile(fileName, null, project.IProject) as CSharpUnresolvedFile;
if (this.UnresolvedTypeSystemForFile == null)
throw new InvalidOperationException("LoadSolutionProjectsThread not yet finished?");
}
示例10: SetUp
public override void SetUp()
{
base.SetUp();
unresolvedFile = new CSharpUnresolvedFile();
unresolvedFile.RootUsingScope.Usings.Add(MakeReference("System"));
unresolvedFile.RootUsingScope.Usings.Add(MakeReference("System.Collections.Generic"));
unresolvedFile.RootUsingScope.Usings.Add(MakeReference("System.Linq"));
convertVisitor = new CodeDomConvertVisitor();
convertVisitor.AllowSnippetNodes = false;
convertVisitor.UseFullyQualifiedTypeNames = true;
}
示例11: CSharpCompletionContext
private CSharpCompletionContext(ITextEditor editor, IList<string> conditionalSymbols, ICompilation compilation, IProjectContent projectContent, IDocument document, CSharpUnresolvedFile unresolvedFile, TextLocation caretLocation)
{
Debug.Assert(editor != null);
Debug.Assert(unresolvedFile != null);
Debug.Assert(compilation != null);
Debug.Assert(projectContent != null);
Debug.Assert(document != null);
this.Editor = editor;
this.Document = document;
this.ConditionalSymbols = conditionalSymbols;
this.Compilation = compilation;
this.ProjectContent = projectContent;
this.TypeResolveContextAtCaret = unresolvedFile.GetTypeResolveContext(compilation, caretLocation);
this.CompletionContextProvider = new DefaultCompletionContextProvider(document, unresolvedFile);
this.CompletionContextProvider.ConditionalSymbols.AddRange(conditionalSymbols);
}
示例12: MethodParameterDataProvider
public MethodParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IEnumerable<IMethod> m) : base (ext, startOffset)
{
compilation = ext.UnresolvedFileCompilation;
file = ext.CSharpUnresolvedFile;
HashSet<string> alreadyAdded = new HashSet<string> ();
foreach (var method in m) {
if (method.IsConstructor)
continue;
if (!method.IsBrowsable ())
continue;
string str = ambience.GetString (method, OutputFlags.IncludeParameters | OutputFlags.GeneralizeGenerics | OutputFlags.IncludeGenerics);
if (alreadyAdded.Contains (str))
continue;
alreadyAdded.Add (str);
methods.Add (method);
}
methods.Sort (MethodComparer);
}
示例13: Prepare
private void Prepare(string source, Action preparer) {
IProjectContent project = new CSharpProjectContent();
var parser = new CSharpParser();
using (var rdr = new StringReader(source)) {
var pf = new CSharpUnresolvedFile("File.cs");
var syntaxTree = parser.Parse(rdr, pf.FileName);
syntaxTree.AcceptVisitor(new TypeSystemConvertVisitor(pf));
project = project.AddOrUpdateFiles(pf);
}
project = project.AddAssemblyReferences(new[] { Files.Mscorlib });
var compilation = project.CreateCompilation();
AllTypes = compilation.MainAssembly.TopLevelTypeDefinitions.SelectMany(SelfAndNested).ToDictionary(t => t.ReflectionName);
var er = new MockErrorReporter(true);
Metadata = new MetadataImporter(er, compilation, new CompilerOptions());
preparer();
Metadata.Prepare(compilation.GetAllTypeDefinitions());
Assert.That(er.AllMessages, Is.Empty, "Should not generate errrors");
}
示例14: CreateShortType
public AstType CreateShortType (ICompilation compilation, CSharpUnresolvedFile parsedFile, TextLocation loc, IType fullType)
{
var csResolver = parsedFile.GetResolver (compilation, loc);
var builder = new ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder (csResolver);
return builder.ConvertType (fullType);
}
示例15: Init
void Init(string code)
{
syntaxTree = SyntaxTree.Parse(code, "test.cs");
unresolvedFile = syntaxTree.ToTypeSystem();
compilation = TypeSystemHelper.CreateCompilation(unresolvedFile);
findReferences = new FindReferences();
}