当前位置: 首页>>代码示例>>C#>>正文


C# SemanticModel.LookupSymbols方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.SemanticModel.LookupSymbols方法的典型用法代码示例。如果您正苦于以下问题:C# SemanticModel.LookupSymbols方法的具体用法?C# SemanticModel.LookupSymbols怎么用?C# SemanticModel.LookupSymbols使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.SemanticModel的用法示例。


在下文中一共展示了SemanticModel.LookupSymbols方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateTarget

 ExpressionSyntax GenerateTarget(SemanticModel model, BinaryExpressionSyntax node)
 {
     var symbols = model.LookupSymbols(node.SpanStart).OfType<IMethodSymbol>();
     if (!symbols.Any() || HasDifferentEqualsMethod(symbols))
         return SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ParseExpression("object"), SyntaxFactory.IdentifierName("Equals"));
     else
         return SyntaxFactory.IdentifierName("Equals");
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:8,代码来源:ConvertEqualityOperatorToEqualsCodeRefactoringProvider.cs

示例2: ReduceQualifiedTypeName

 public static string ReduceQualifiedTypeName(
     this ITypeSymbol type,SemanticModel semantic,int classDeclarationPosition)
 {
     // one problem is that the type could be from a different semantic model
     // (one that was created before) so we search the type in the
     // new model and if we find it use the new one instead
     var typeInSemanticModel = semantic.LookupSymbols(0, name: type.Name)
         .OfType<ITypeSymbol>()
         .FirstOrDefault();
     if (typeInSemanticModel != null)
         type = typeInSemanticModel;
     return type.ToMinimalDisplayString(semantic, classDeclarationPosition);
 }
开发者ID:pgenfer,项目名称:mixinSharp,代码行数:13,代码来源:TypeSymbolExtension.cs

示例3: GetProgramElementNameThatMatchStringLiteral

        private static string GetProgramElementNameThatMatchStringLiteral(LiteralExpressionSyntax stringLiteral, SemanticModel semanticModel)
        {
            var programElementName = GetParameterNameThatMatchStringLiteral(stringLiteral);

            if (!Found(programElementName))
            {
                var literalValueText = stringLiteral.Token.ValueText;
                var symbol = semanticModel.LookupSymbols(stringLiteral.Token.SpanStart, null, literalValueText).FirstOrDefault();

                programElementName = symbol?.ToDisplayParts().LastOrDefault(IncludeOnlyPartsThatAreName).ToString();
            }

            return programElementName;
        }
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:14,代码来源:NameOfAnalyzer.cs

示例4: CreateCompletionData

		protected virtual IEnumerable<CompletionData> CreateCompletionData (CompletionEngine engine, SemanticModel semanticModel, int position, INamedTypeSymbol enclosingType, SyntaxToken token, bool afterPartialKeyword, CancellationToken cancellationToken)
		{
			var symbols = semanticModel.LookupSymbols(position, container: enclosingType)
				.OfType<IMethodSymbol>()
				.Where(m => IsPartial(m) && m.PartialImplementationPart == null);

			var list = new List<CompletionData> ();

			var declarationBegin = afterPartialKeyword ? token.Parent.SpanStart : position - 1;
			foreach (var m in symbols) {
				var data = engine.Factory.CreatePartialCompletionData (
					this,
					declarationBegin,
					enclosingType,
					m,
					afterPartialKeyword
				);
				list.Add (data); 
			}
			return list;
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:21,代码来源:PartialContextHandler.cs

示例5: GetProgramElementNameThatMatchStringLiteral

        private static string GetProgramElementNameThatMatchStringLiteral(LiteralExpressionSyntax stringLiteral, SemanticModel semanticModel)
        {
            var programElementName = GetParameterNameThatMatchStringLiteral(stringLiteral);

            if (!Found(programElementName))
            {
                var literalValueText = stringLiteral.Token.ValueText;
                var symbol = semanticModel.LookupSymbols(stringLiteral.Token.SpanStart, null, literalValueText).FirstOrDefault();

                if (symbol?.Kind == SymbolKind.Local)
                {
                    var symbolSpan = symbol.Locations.Min(i => i.SourceSpan);
                    if (symbolSpan.CompareTo(stringLiteral.Token.Span) > 0)
                        return string.Empty;
                }

                programElementName = symbol?.ToDisplayParts().LastOrDefault(AnalyzerExtensions.IsName).ToString();
            }

            return programElementName;
        }
开发者ID:nikolasmagno,项目名称:code-cracker,代码行数:21,代码来源:NameOfAnalyzer.cs

示例6: DetectSynchronousUsages

        private static string DetectSynchronousUsages(IMethodSymbol methodCallSymbol, SemanticModel semanticModel)
        {
            var list = semanticModel.LookupSymbols(0, container: methodCallSymbol.ContainingType,
                                includeReducedExtensionMethods: true);

            var name = methodCallSymbol.Name;

            if (methodCallSymbol.ContainingType == null)
            {
                return "None";
            }

            if (methodCallSymbol.ContainingType.Name == "Thread" && name == "Sleep")
            {
                return "Task.Delay";
            }
            // Parameter Sifir olmasi lazim!!!!!
            else if (methodCallSymbol.ContainingType.Name == "Task" && name == "Wait")
            {
                return "await";
            }
            else if (methodCallSymbol.ContainingType.Name == "Task" && name == "WaitAll")
            {
                return "Task.WhenAll";
            }
            else if (methodCallSymbol.ContainingType.Name == "Task" && name == "WaitAny")
            {
                return "Task.WhenAny";
            }

            foreach (var tmp in list)
            {
                if (tmp.Name.Equals(name + "Async"))
                {
                    return tmp.Name;
                }
            }

            return "None";
        }
开发者ID:modulexcite,项目名称:AsyncFixer,代码行数:40,代码来源:LongRunningAnalyzer.cs

示例7: FindIssuesInAccessor

        static bool FindIssuesInAccessor(SemanticModel semanticModel, AccessorDeclarationSyntax accessor)
        {
            var body = accessor.Body;
            if (!IsEligible(body))
                return false;

            if (body.Statements.Any())
            {
                var foundValueSymbol = semanticModel.LookupSymbols(body.Statements.First().SpanStart, null, "value").FirstOrDefault();
                if (foundValueSymbol == null)
                    return false;

                foreach (var valueRef in body.DescendantNodes().OfType<IdentifierNameSyntax>().Where(ins => ins.Identifier.ValueText == "value"))
                {
                    var valueRefSymbol = semanticModel.GetSymbolInfo(valueRef).Symbol;
                    if (foundValueSymbol.Equals(valueRefSymbol))
                        return false;
                }
            }

            return true;
        }
开发者ID:pgrefviau,项目名称:RefactoringEssentials,代码行数:22,代码来源:ValueParameterNotUsedAnalyzer.cs

示例8: GetProgramElementNameThatMatchStringLiteral

        private static string GetProgramElementNameThatMatchStringLiteral(LiteralExpressionSyntax stringLiteral, SemanticModel semanticModel, out bool externalSymbol)
        {
            externalSymbol = false;
            var programElementName = GetParameterNameThatMatchStringLiteral(stringLiteral);
            if (!Found(programElementName))
            {
                var literalValueText = stringLiteral.Token.ValueText;
                var symbol = semanticModel.LookupSymbols(stringLiteral.Token.SpanStart, null, literalValueText).FirstOrDefault();
                if (symbol == null) return null;
                externalSymbol = !symbol.Locations.Any(l => l.IsInSource);

                if (symbol.Kind == SymbolKind.Local)
                {
                    var symbolSpan = symbol.Locations.Min(i => i.SourceSpan);
                    if (symbolSpan.CompareTo(stringLiteral.Token.Span) > 0)
                        return null;
                }

                programElementName = symbol.ToDisplayParts(NameOfSymbolDisplayFormat).LastOrDefault(AnalyzerExtensions.IsName).ToString();
            }

            return programElementName;
        }
开发者ID:Vossekop,项目名称:code-cracker,代码行数:23,代码来源:NameOfAnalyzer.cs

示例9: TryGetIndexers

        private bool TryGetIndexers(int position, SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken, out IEnumerable<IPropertySymbol> indexers, out ITypeSymbol expressionType)
        {
            expressionType = semanticModel.GetTypeInfo(expression, cancellationToken).Type;

            if (expressionType == null)
            {
                indexers = null;
                return false;
            }

            if (expressionType is IErrorTypeSymbol)
            {
                expressionType = (expressionType as IErrorTypeSymbol).CandidateSymbols.FirstOrDefault().GetSymbolType();
            }

            indexers = semanticModel.LookupSymbols(position, expressionType, WellKnownMemberNames.Indexer).OfType<IPropertySymbol>();
            return true;
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:18,代码来源:ElementAccessExpressionSignatureHelpProvider.cs

示例10: GetCompletionsOffOfExplicitInterfaceAsync

		private Task<IEnumerable<CompletionData>> GetCompletionsOffOfExplicitInterfaceAsync(
			CompletionEngine engine, Document document, SemanticModel semanticModel, int position, NameSyntax name, CancellationToken cancellationToken)
		{
			// Bind the interface name which is to the left of the dot
			var syntaxTree = semanticModel.SyntaxTree;
			var nameBinding = semanticModel.GetSymbolInfo(name, cancellationToken);
			// var context = CSharpSyntaxContext.CreateContext(document.Project.Solution.Workspace, semanticModel, position, cancellationToken);

			var symbol = nameBinding.Symbol as ITypeSymbol;
			if (symbol == null || symbol.TypeKind != TypeKind.Interface)
			{
				return Task.FromResult (Enumerable.Empty<CompletionData> ());
			}

			var members = semanticModel.LookupSymbols (
	              position: name.SpanStart,
	              container: symbol)
				.Where (s => !s.IsStatic);
			//	.FilterToVisibleAndBrowsableSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation);

			// We're going to create a entry for each one, including the signature
			var completions = new List<CompletionData>();

//			var signatureDisplayFormat =
//				new SymbolDisplayFormat(
//					genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
//					memberOptions:
//					SymbolDisplayMemberOptions.IncludeParameters,
//					parameterOptions:
//					SymbolDisplayParameterOptions.IncludeName |
//					SymbolDisplayParameterOptions.IncludeType |
//					SymbolDisplayParameterOptions.IncludeParamsRefOut,
//					miscellaneousOptions:
//					SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
//					SymbolDisplayMiscellaneousOptions.UseSpecialTypes);

			var namePosition = name.SpanStart;

			// var text = await context.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
			// var textChangeSpan = GetTextChangeSpan(text, context.Position);

			foreach (var member in members)
			{
				// var displayString = member.ToMinimalDisplayString(semanticModel, namePosition, signatureDisplayFormat);
				// var memberCopied = member;
				// var insertionText = displayString;

				completions.Add(engine.Factory.CreateSymbolCompletionData (this, member)

					/*new SymbolCompletionItem(
					this,
					displayString,
					insertionText: insertionText,
					filterSpan: textChangeSpan,
					position: position,
					symbols: new List<ISymbol> { member },
					context: context) */);
			}

			return Task.FromResult ((IEnumerable<CompletionData>)completions);
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:61,代码来源:ExplicitInterfaceContextHandler.cs

示例11: GetName

 static string GetName(SemanticModel model, TextSpan span, string[] variableNames)
 {
     var symbols = model.LookupSymbols(span.Start).ToList();
     for (int i = 0; i < 1000; i++)
     {
         foreach (var vn in variableNames)
         {
             string id = i > 0 ? vn + i : vn;
             if (symbols.All(s => s.Name != id))
                 return id;
         }
     }
     return null;
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:14,代码来源:ConvertForeachToForCodeRefactoringProvider.cs

示例12: TryGetIndexers

        private bool TryGetIndexers(int position, SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken, out IEnumerable<IPropertySymbol> indexers, out ITypeSymbol expressionType)
        {
            expressionType = semanticModel.GetTypeInfo(expression, cancellationToken).Type;

            if (expressionType == null)
            {
                indexers = null;
                return false;
            }

            if (expressionType is IErrorTypeSymbol)
            {
                // If `expression` is a QualifiedNameSyntax then GetTypeInfo().Type won't have any CandidateSymbols, so
                // we should then fall back to getting the actual symbol for the expression.
                expressionType = (expressionType as IErrorTypeSymbol).CandidateSymbols.FirstOrDefault().GetSymbolType()
                    ?? semanticModel.GetSymbolInfo(expression).GetAnySymbol().GetSymbolType();
            }

            indexers = semanticModel.LookupSymbols(position, expressionType, WellKnownMemberNames.Indexer).OfType<IPropertySymbol>();
            return true;
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:21,代码来源:ElementAccessExpressionSignatureHelpProvider.cs

示例13: ComputePossibleImplicitUsageConflicts

        public IEnumerable<Location> ComputePossibleImplicitUsageConflicts(
            ISymbol renamedSymbol,
            SemanticModel semanticModel,
            Location originalDeclarationLocation,
            int newDeclarationLocationStartingPosition,
            CancellationToken cancellationToken)
        {
            // TODO: support other implicitly used methods like dispose

            if ((renamedSymbol.Name == "MoveNext" || renamedSymbol.Name == "GetEnumerator" || renamedSymbol.Name == "Current") && renamedSymbol.GetAllTypeArguments().Length == 0)
            {
                // TODO: partial methods currently only show the location where the rename happens as a conflict.
                //       Consider showing both locations as a conflict.
                var baseType = renamedSymbol.ContainingType.GetBaseTypes().FirstOrDefault();
                if (baseType != null)
                {
                    var implicitSymbols = semanticModel.LookupSymbols(
                        newDeclarationLocationStartingPosition,
                        baseType,
                        renamedSymbol.Name)
                            .Where(sym => !sym.Equals(renamedSymbol));

                    foreach (var symbol in implicitSymbols)
                    {
                        if (symbol.GetAllTypeArguments().Length != 0)
                        {
                            continue;
                        }

                        if (symbol.Kind == SymbolKind.Method)
                        {
                            var method = (IMethodSymbol)symbol;

                            if (symbol.Name == "MoveNext")
                            {
                                if (!method.ReturnsVoid && !method.Parameters.Any() && method.ReturnType.SpecialType == SpecialType.System_Boolean)
                                {
                                    return SpecializedCollections.SingletonEnumerable(originalDeclarationLocation);
                                }
                            }
                            else if (symbol.Name == "GetEnumerator")
                            {
                                // we are a bit pessimistic here. 
                                // To be sure we would need to check if the returned type is having a MoveNext and Current as required by foreach
                                if (!method.ReturnsVoid &&
                                    !method.Parameters.Any())
                                {
                                    return SpecializedCollections.SingletonEnumerable(originalDeclarationLocation);
                                }
                            }
                        }
                        else if (symbol.Kind == SymbolKind.Property && symbol.Name == "Current")
                        {
                            var property = (IPropertySymbol)symbol;

                            if (!property.Parameters.Any() && !property.IsWriteOnly)
                            {
                                return SpecializedCollections.SingletonEnumerable(originalDeclarationLocation);
                            }
                        }
                    }
                }
            }

            return SpecializedCollections.EmptyEnumerable<Location>();
        }
开发者ID:nemec,项目名称:roslyn,代码行数:66,代码来源:CSharpRenameRewriterLanguageService.cs

示例14: GetAction

 CodeAction GetAction(Document document, SemanticModel model, SyntaxNode root, SyntaxNode node, MethodDeclarationSyntax method)
 {
     return CodeActionFactory.Create(node.Span, DiagnosticSeverity.Info, GettextCatalog.GetString("Extract anonymous method"), t2 =>
     {
         var identifier = SyntaxFactory.IdentifierName(NameGenerator.EnsureUniqueness("Method", model.LookupSymbols(node.SpanStart).Select(s => s.Name)));
         var surroundingMemberDeclaration = node.GetAncestor<MemberDeclarationSyntax>();
         var rootWithTrackedMember = root.TrackNodes(node, surroundingMemberDeclaration);
         var newRoot = rootWithTrackedMember.ReplaceNode(rootWithTrackedMember.GetCurrentNode(node), identifier);
         newRoot = newRoot
             .InsertNodesBefore(newRoot.GetCurrentNode(surroundingMemberDeclaration),
             new[] { method.WithTrailingTrivia(surroundingMemberDeclaration.GetTrailingTrivia()) });
         return Task.FromResult(document.WithSyntaxRoot(newRoot));
     });
 }
开发者ID:ceddlyburge,项目名称:RefactoringEssentials,代码行数:14,代码来源:ExtractAnonymousMethodCodeRefactoringProvider.cs

示例15: HandleTypeParameterCase

		ParameterHintingResult HandleTypeParameterCase(SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken)
		{
			var result = new ParameterHintingResult(node.SpanStart);
			string typeName;
			var gns = node as GenericNameSyntax;
			if (gns != null) {
				typeName = gns.Identifier.ToString ();
			} else {
				typeName = node.ToString ();
			}

			foreach (var cand in semanticModel.LookupSymbols (node.SpanStart).OfType<INamedTypeSymbol> ()) {
				if (cand.TypeParameters.Length == 0)
					continue;
				if (cand.Name == typeName || cand.GetFullName () == typeName)
					result.AddData(factory.CreateTypeParameterDataProvider(cand));
			}

			if (result.Count == 0) {
				foreach (var cand in semanticModel.LookupSymbols (node.SpanStart).OfType<IMethodSymbol> ()) {
					if (cand.TypeParameters.Length == 0)
						continue;
					if (cand.Name == typeName)
						result.AddData (factory.CreateTypeParameterDataProvider (cand));
				}
			}
			return result;
		}
开发者ID:pjcollins,项目名称:monodevelop,代码行数:28,代码来源:ParameterHintingEngine.cs


注:本文中的Microsoft.CodeAnalysis.SemanticModel.LookupSymbols方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。