本文整理汇总了C#中ITypeResolveContext.Synchronize方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeResolveContext.Synchronize方法的具体用法?C# ITypeResolveContext.Synchronize怎么用?C# ITypeResolveContext.Synchronize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeResolveContext
的用法示例。
在下文中一共展示了ITypeResolveContext.Synchronize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Resolve
public static ResolveResult Resolve(ITypeResolveContext context, CSharpParsedFile parsedFile, CompilationUnit cu, TextLocation location,
CancellationToken cancellationToken = default(CancellationToken))
{
AstNode node = cu.GetNodeAt(location);
if (node == null)
return null;
AstNode resolvableNode;
if (node is AstType) {
resolvableNode = node;
if (resolvableNode.Parent is ComposedType) {
while (resolvableNode.Parent is ComposedType)
resolvableNode = resolvableNode.Parent;
//node is preffered over the resolvable node. Which shouldn't be done in the case of nullables, arrays etc.
node = resolvableNode;
}
} else if (node is Identifier) {
resolvableNode = node.Parent;
} else if (node.NodeType == NodeType.Token) {
if (node.Parent is ConstructorInitializer) {
resolvableNode = node.Parent;
} else {
return null;
}
} else {
// don't resolve arbitrary nodes - we don't want to show tooltips for everything
return null;
}
InvocationExpression parentInvocation = null;
if ((resolvableNode is IdentifierExpression || resolvableNode is MemberReferenceExpression || resolvableNode is PointerReferenceExpression)) {
// we also need to resolve the invocation
parentInvocation = resolvableNode.Parent as InvocationExpression;
}
IResolveVisitorNavigator navigator;
if (parentInvocation != null)
navigator = new NodeListResolveVisitorNavigator(new[] { resolvableNode, parentInvocation });
else
navigator = new NodeListResolveVisitorNavigator(new[] { resolvableNode });
using (var ctx = context.Synchronize()) {
CSharpResolver resolver = new CSharpResolver(ctx, cancellationToken);
ResolveVisitor v = new ResolveVisitor(resolver, parsedFile, navigator);
v.Scan(cu);
// Prefer the RR from the token itself, if it was assigned a ResolveResult
// (this can happen with the identifiers in various nodes such as catch clauses or foreach statements)
ResolveResult rr = v.GetResolveResult(node) ?? v.GetResolveResult(resolvableNode);
if (rr is MethodGroupResolveResult && parentInvocation != null)
return v.GetResolveResult(parentInvocation);
else
return rr;
}
}
示例2: FindReferencesInFile
/// <summary>
/// Finds all references in the given file.
/// </summary>
/// <param name="searchScopes">The search scopes for which to look.</param>
/// <param name="parsedFile">The type system representation of the file being searched.</param>
/// <param name="compilationUnit">The compilation unit of the file being searched.</param>
/// <param name="context">The type resolve context to use for resolving the file.</param>
/// <param name="callback">Callback used to report the references that were found.</param>
public void FindReferencesInFile(IList<IFindReferenceSearchScope> searchScopes, CSharpParsedFile parsedFile, CompilationUnit compilationUnit,
ITypeResolveContext context, FoundReferenceCallback callback)
{
if (searchScopes == null)
throw new ArgumentNullException("searchScopes");
if (parsedFile == null)
throw new ArgumentNullException("parsedFile");
if (compilationUnit == null)
throw new ArgumentNullException("compilationUnit");
if (context == null)
throw new ArgumentNullException("context");
this.CancellationToken.ThrowIfCancellationRequested();
if (searchScopes.Count == 0)
return;
using (var ctx = context.Synchronize()) {
IResolveVisitorNavigator navigator;
if (searchScopes.Count == 1)
navigator = searchScopes[0].GetNavigator(callback);
else
navigator = new CompositeResolveVisitorNavigator(searchScopes.Select(s => s.GetNavigator(callback)).ToArray());
navigator = new DetectSkippableNodesNavigator(navigator, compilationUnit);
CSharpResolver resolver = new CSharpResolver(ctx, this.CancellationToken);
ResolveVisitor v = new ResolveVisitor(resolver, parsedFile, navigator);
v.Scan(compilationUnit);
}
}