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


C# ISymbol.GetParameters方法代码示例

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


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

示例1: CheckParameters

        static void CheckParameters(SyntaxNodeAnalysisContext ctx, ISymbol member, List<ISymbol> overloads, SeparatedSyntaxList<ParameterSyntax> parameterListNodes)
        {
            var memberParameters = member.GetParameters();
            for (int i = 0; i < memberParameters.Length; i++)
            {
                if (!memberParameters[i].IsOptional)
                    continue;

                foreach (var overload in overloads)
                {
                    if (overload.GetParameters().Length != i)
                        continue;
                    bool equal = true;
                    for (int j = 0; j < i; j++)
                    {
                        if (overload.GetParameters()[j].Type != memberParameters[j].Type)
                        {
                            equal = false;
                            break;
                        }
                    }
                    if (equal)
                    {
                        ctx.ReportDiagnostic( Diagnostic.Create(
                            descriptor,
                            parameterListNodes[i].GetLocation(),
                            member.IsKind(SymbolKind.Method) ? GettextCatalog.GetString("Method") : GettextCatalog.GetString("Indexer")
                        ));
                    }
                }
            }
        }
开发者ID:ceddlyburge,项目名称:RefactoringEssentials,代码行数:32,代码来源:MethodOverloadWithOptionalParameterAnalyzer.cs

示例2: GenerateMember

        protected override ISymbol GenerateMember(ISymbol member, INamedTypeSymbol containingType, Document document, MemberInsertionCompletionItem item, CancellationToken cancellationToken)
        {
            var syntaxFactory = document.GetLanguageService<SyntaxGenerator>();
            var semanticModel = document.GetSemanticModelAsync(cancellationToken).WaitAndGetResult(cancellationToken);

            return CodeGenerationSymbolFactory.CreateMethodSymbol(attributes: new List<AttributeData>(),
                accessibility: Accessibility.NotApplicable,
                modifiers: item.Modifiers,
                returnType: semanticModel.Compilation.GetSpecialType(SpecialType.System_Void),
                explicitInterfaceSymbol: null,
                name: member.Name,
                typeParameters: ((IMethodSymbol)member).TypeParameters,
                parameters: member.GetParameters().Select(p => CodeGenerationSymbolFactory.CreateParameterSymbol(p.GetAttributes(), p.RefKind, p.IsParams, p.Type, p.Name)).ToList(),
                statements: syntaxFactory.CreateThrowNotImplementedStatementBlock(semanticModel.Compilation));
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:15,代码来源:AbstractPartialCompletionProvider.cs

示例3: CheckParameters

        static void CheckParameters(SyntaxNodeAnalysisContext nodeContext, ISymbol ir, IEnumerable<ArgumentSyntax> arguments)
        {
            if (ir == null)
                return;
            var parameters = ir.GetParameters();
            int i = 0;

            foreach (var arg in arguments)
            {
                var na = arg.NameColon;
                if (na != null)
                {
                    if (i >= parameters.Length || na.Name.ToString() != parameters[i].Name)
                        break;
                    nodeContext.ReportDiagnostic(Diagnostic.Create(descriptor, na.GetLocation()));
                }
                i++;
            }
        }
开发者ID:ceddlyburge,项目名称:RefactoringEssentials,代码行数:19,代码来源:RedundantArgumentNameAnalyzer.cs

示例4: HasViolatingParameters

        private static bool HasViolatingParameters(ISymbol symbol)
        {
            var parameters = symbol.GetParameters();

            // If there is only one parameter, then return an empty collection
            if (!parameters.Skip(1).Any())
            {
                return false;
            }

            return parameters.GroupBy(item => item.Name, StringComparer.InvariantCultureIgnoreCase).Where((group) => group.Count() > 1).Any();
        }
开发者ID:pheede,项目名称:roslyn,代码行数:12,代码来源:CA1708DiagnosticAnalyzer.cs

示例5: CreateItem

        private CompletionItem CreateItem(
            Workspace workspace, SemanticModel semanticModel, ISymbol symbol, SyntaxToken token, StringBuilder builder)
        {
            int position = token.SpanStart;

            if (symbol is INamespaceOrTypeSymbol && token.IsKind(SyntaxKind.DotToken))
            {
                // Handle qualified namespace and type names.

                builder.Append(symbol.ToDisplayString(QualifiedCrefFormat));
            }
            else
            {
                // Handle unqualified namespace and type names, or member names.

                builder.Append(symbol.ToMinimalDisplayString(semanticModel, position, CrefFormat));

                var parameters = symbol.GetParameters();
                if (!parameters.IsDefaultOrEmpty)
                {
                    // Note: we intentionally don't add the "params" modifier for any parameters.

                    builder.Append(symbol.IsIndexer() ? '[' : '(');

                    for (int i = 0; i < parameters.Length; i++)
                    {
                        if (i > 0)
                        {
                            builder.Append(", ");
                        }

                        var parameter = parameters[i];

                        if (parameter.RefKind == RefKind.Out)
                        {
                            builder.Append("out ");
                        }
                        else if (parameter.RefKind == RefKind.Ref)
                        {
                            builder.Append("ref ");
                        }

                        builder.Append(parameter.Type.ToMinimalDisplayString(semanticModel, position));
                    }

                    builder.Append(symbol.IsIndexer() ? ']' : ')');
                }
            }

            var symbolText = builder.ToString();

            var insertionText = builder
                .Replace('<', '{')
                .Replace('>', '}')
                .ToString();

            return SymbolCompletionItem.Create(
                displayText: insertionText,
                insertionText: insertionText,
                symbol: symbol,
                contextPosition: position,
                sortText: symbolText,
                rules: GetRules(insertionText));
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:64,代码来源:CrefCompletionProvider.cs

示例6: CreateCompensatingSignatureChange

        private static SignatureChange CreateCompensatingSignatureChange(ISymbol declarationSymbol, SignatureChange updatedSignature)
        {
            if (declarationSymbol.GetParameters().Count() > updatedSignature.OriginalConfiguration.ToListOfParameters().Count)
            {
                var origStuff = updatedSignature.OriginalConfiguration.ToListOfParameters();
                var newStuff = updatedSignature.UpdatedConfiguration.ToListOfParameters();

                var realStuff = declarationSymbol.GetParameters();

                var bonusParameters = realStuff.Skip(origStuff.Count);

                origStuff.AddRange(bonusParameters);
                newStuff.AddRange(bonusParameters);

                var newOrigParams = ParameterConfiguration.Create(origStuff, updatedSignature.OriginalConfiguration.ThisParameter != null);
                var newUpdatedParams = ParameterConfiguration.Create(newStuff, updatedSignature.OriginalConfiguration.ThisParameter != null);
                updatedSignature = new SignatureChange(newOrigParams, newUpdatedParams);
            }

            return updatedSignature;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:21,代码来源:AbstractChangeSignatureService.cs

示例7: PermuteArguments

        protected static List<IUnifiedArgumentSyntax> PermuteArguments(
            Document document,
            ISymbol declarationSymbol,
            List<IUnifiedArgumentSyntax> arguments,
            SignatureChange updatedSignature,
            bool isReducedExtensionMethod = false)
        {
            // 1. Determine which parameters are permutable

            var declarationParameters = declarationSymbol.GetParameters().ToList();
            var declarationParametersToPermute = GetParametersToPermute(arguments, declarationParameters, isReducedExtensionMethod);
            var argumentsToPermute = arguments.Take(declarationParametersToPermute.Count).ToList();

            // 2. Create an argument to parameter map, and a parameter to index map for the sort.
            var argumentToParameterMap = new Dictionary<IUnifiedArgumentSyntax, IParameterSymbol>();
            var parameterToIndexMap = new Dictionary<IParameterSymbol, int>();

            for (int i = 0; i < declarationParametersToPermute.Count; i++)
            {
                var decl = declarationParametersToPermute[i];
                var arg = argumentsToPermute[i];

                argumentToParameterMap[arg] = decl;
                var originalIndex = declarationParameters.IndexOf(decl);

                var updatedIndex = updatedSignature.GetUpdatedIndex(originalIndex);

                // If there's no value, then we may be handling a method with more parameters than the original symbol (like BeginInvoke).
                parameterToIndexMap[decl] = updatedIndex.HasValue ? updatedIndex.Value : -1;
            }

            // 3. Sort the arguments that need to be reordered

            argumentsToPermute.Sort((a1, a2) => { return parameterToIndexMap[argumentToParameterMap[a1]].CompareTo(parameterToIndexMap[argumentToParameterMap[a2]]); });

            // 4. Add names to arguments where necessary.

            var newArguments = new List<IUnifiedArgumentSyntax>();
            int expectedIndex = 0 + (isReducedExtensionMethod ? 1 : 0);
            bool seenNamedArgument = false;

            foreach (var argument in argumentsToPermute)
            {
                var param = argumentToParameterMap[argument];
                var actualIndex = updatedSignature.GetUpdatedIndex(declarationParameters.IndexOf(param));

                if (!actualIndex.HasValue)
                {
                    continue;
                }

                if ((seenNamedArgument || actualIndex != expectedIndex) && !argument.IsNamed)
                {
                    newArguments.Add(argument.WithName(param.Name).WithAdditionalAnnotations(Formatter.Annotation));
                    seenNamedArgument = true;
                }
                else
                {
                    newArguments.Add(argument);
                }

                seenNamedArgument |= argument.IsNamed;
                expectedIndex++;
            }

            // 5. Add the remaining arguments. These will already have names or be params arguments, but may have been removed.

            bool removedParams = updatedSignature.OriginalConfiguration.ParamsParameter != null && updatedSignature.UpdatedConfiguration.ParamsParameter == null;

            for (int i = declarationParametersToPermute.Count; i < arguments.Count; i++)
            {
                if (!arguments[i].IsNamed && removedParams && i >= updatedSignature.UpdatedConfiguration.ToListOfParameters().Count)
                {
                    break;
                }

                if (!arguments[i].IsNamed || updatedSignature.UpdatedConfiguration.ToListOfParameters().Any(p => p.Name == arguments[i].GetName()))
                {
                    newArguments.Add(arguments[i]);
                }
            }

            return newArguments;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:84,代码来源:AbstractChangeSignatureService.cs

示例8: GetIdForMemberAsync

        public static async Task<GraphNodeId> GetIdForMemberAsync(ISymbol member, Solution solution, CancellationToken cancellationToken)
        {
            var partials = new List<GraphNodeId>();

            partials.AddRange(await GetPartialsForNamespaceAndTypeAsync(member.ContainingType, true, solution, cancellationToken).ConfigureAwait(false));

            var parameters = member.GetParameters();
            if (parameters.Any() || member.GetArity() > 0)
            {
                var memberPartials = new List<GraphNodeId>();

                memberPartials.Add(GraphNodeId.GetPartial(CodeQualifiedName.Name, member.MetadataName));

                if (member.GetArity() > 0)
                {
                    memberPartials.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.GenericParameterCountIdentifier, member.GetArity().ToString()));
                }

                if (parameters.Any())
                {
                    var parameterTypeIds = new List<GraphNodeId>();
                    foreach (var p in parameters)
                    {
                        var parameterIds = await GetPartialsForNamespaceAndTypeAsync(p.Type, true, solution, cancellationToken).ConfigureAwait(false);
                        var nodes = parameterIds.ToList();
                        if (p.IsRefOrOut())
                        {
                            nodes.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.ParamKind, ParamKind.Ref));
                        }

                        parameterTypeIds.Add(GraphNodeId.GetNested(nodes.ToArray()));
                    }

                    IMethodSymbol methodSymbol = member as IMethodSymbol;
                    if (methodSymbol != null && methodSymbol.MethodKind == MethodKind.Conversion)
                    {
                        // For explicit/implicit conversion operators, we need to include the return type in the method Id,
                        // because there can be several conversion operators with same parameters and only differ by return type.
                        // For example,
                        // 
                        //     public class Class1
                        //     {
                        //         public static explicit (explicit) operator int(Class1 c) { ... }
                        //         public static explicit (explicit) operator double(Class1 c) { ... }
                        //     }

                        var nodes = await GetPartialsForNamespaceAndTypeAsync(methodSymbol.ReturnType, true, solution, cancellationToken).ConfigureAwait(false);
                        List<GraphNodeId> returnTypePartial = nodes.ToList();
                        returnTypePartial.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.ParamKind, Microsoft.VisualStudio.GraphModel.CodeSchema.ParamKind.Return));

                        GraphNodeId returnCollection = GraphNodeId.GetNested(returnTypePartial.ToArray());
                        parameterTypeIds.Add(returnCollection);
                    }

                    memberPartials.Add(GraphNodeId.GetArray(
                                       CodeGraphNodeIdName.OverloadingParameters,
                                       parameterTypeIds.ToArray()));
                }

                partials.Add(GraphNodeId.GetPartial(
                            CodeGraphNodeIdName.Member,
                            MakeCollectionIfNecessary(false, memberPartials.ToArray())));
            }
            else
            {
                partials.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Member, member.MetadataName));
            }

            return GraphNodeId.GetNested(partials.ToArray());
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:70,代码来源:GraphNodeIdCreation.cs

示例9: MatchesParameter

        private static bool MatchesParameter(ISymbol symbol, string stringArgumentValue)
        {
            foreach (IParameterSymbol parameter in symbol.GetParameters())
            {
                if (parameter.Name == stringArgumentValue)
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:bkoelman,项目名称:roslyn-analyzers,代码行数:12,代码来源:InstantiateArgumentExceptionsCorrectly.cs

示例10: HasSameParameterTypes

        private bool HasSameParameterTypes(ISymbol operator1, ISymbol operator2)
        {
            var parameters1 = operator1.GetParameters();
            var parameters2 = operator2.GetParameters();

            if (parameters1.Length != parameters2.Length)
            {
                return false;
            }

            for (var i = 0; i < parameters1.Length; i++)
            {
                if (!parameters1[i].Type.Equals(parameters2[i].Type))
                {
                    return false;
                }
            }

            return true;
        }
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:20,代码来源:OperatorsShouldHaveSymmetricalOverloads.cs

示例11: Init

		void Init (ISymbol member)
		{
			if (member == null)
				throw new ArgumentNullException ("member");
			FillDocumentation (GetBaseDocumentation (member));
			//			if (provider != null && !member.Location.IsEmpty && member.BodyRegion.EndLine > 1) {
			//				LineSegment start = data.Document.GetLine (member.Region.BeginLine);
			//				LineSegment end = data.Document.GetLine (member.BodyRegion.EndLine);
			//				if (start != null && end != null) {
			//					var result = provider.ParseFile ("class A {" + data.Document.GetTextAt (start.Offset, end.EndOffset - start.Offset) + "}");
			//					result.AcceptVisitor (visitor, null);
			//				}
			//			}
			foreach (var macro in DocConfig.Instance.Macros) {
				tags.Add (macro.Key, macro.Value);
			}
			if (member.ContainingType != null) {
				tags ["DeclaringType"] = "<see cref=\"" + member.ContainingType.GetDocumentationCommentId () + "\"/>";
				switch (member.ContainingType.TypeKind) {
				case TypeKind.Class:
					tags ["DeclaringTypeKind"] = "class";
					break;
				case TypeKind.Delegate:
					tags ["DeclaringTypeKind"] = "delegate";
					break;
				case TypeKind.Enum:
					tags ["DeclaringTypeKind"] = "enum";
					break;
				case TypeKind.Interface:
					tags ["DeclaringTypeKind"] = "interface";
					break;
				case TypeKind.Struct:
					tags ["DeclaringTypeKind"] = "struct";
					break;
				}
			}
			var returnType = member.GetReturnType ();
			tags ["ReturnType"] = returnType != null ? "<see cref=\"" + returnType.GetDocumentationCommentId () + "\"/>" : "";
			tags ["Member"] = "<see cref=\"" + member.Name + "\"/>";

			
			if (member is IPropertySymbol || member is IMethodSymbol) {
				var parameters = member.GetParameters ();
				var parameterNames = new List<string> (from p in parameters select p.Name);
				tags ["ParameterSentence"] = string.Join (" ", parameterNames.ToArray ());
				StringBuilder paramList = new StringBuilder ();
				for (int i = 0; i < parameterNames.Count; i++) {
					if (i > 0) {
						if (i == parameterNames.Count - 1) {
							paramList.Append (" and ");
						} else {
							paramList.Append (", ");
						}
					}
					paramList.Append (parameterNames [i]);
				}
				tags ["ParameterList"] = paramList.ToString ();
				for (int i = 0; i < parameters.Length; i++) {
					tags ["Parameter" + i + ".Type"] = parameters [i].Type != null ? "<see cref=\"" + parameters [i].Type + "\"/>" : "";
					tags ["Parameter" + i + ".Name"] = "<c>" + parameters [i].Name + "</c>";
				}
				
				var property = member as IPropertySymbol;
				if (property != null) {
					var hasPublicGetter = property.GetMethod != null && property.GetMethod.DeclaredAccessibility != Accessibility.Private;
					var hasPublicSetter = property.SetMethod != null && property.SetMethod.DeclaredAccessibility != Accessibility.Private;

					if (property.GetMethod != null && property.SetMethod != null && hasPublicGetter && hasPublicSetter) {
						tags ["AccessText"] = "Gets or sets";
					} else if (property.GetMethod != null && hasPublicGetter) {
						tags ["AccessText"] = "Gets";
					} else if (hasPublicSetter) {
						tags ["AccessText"] = "Sets";
					} else if (property.GetMethod != null && property.SetMethod != null) {
						tags ["AccessText"] = "Gets or sets";
					} else if (property.GetMethod != null) {
						tags ["AccessText"] = "Gets";
					} else {
						tags ["AccessText"] = "Sets";
					}
				}
			}
			
			SplitWords (member, member.Name);
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:85,代码来源:DocGenerator.cs

示例12: GenerateDoc

		public void GenerateDoc (ISymbol member)
		{
			Init (member);
			
			this.member = member;
			this.currentType = GetType (member);
			DocConfig.Instance.Rules.ForEach (r => r.Run (this, member));
			
			if (member is IPropertySymbol || member is IMethodSymbol) {
				this.currentType = "parameter";
				foreach (var p in member.GetParameters ()) {
					curName = p.Name;
					this.member = member;
					SplitWords (p, p.Name);
					DocConfig.Instance.Rules.ForEach (r => r.Run (this, p));
				}
			}
			
			if (member is IMethodSymbol) {
				var method = (IMethodSymbol)member;
				int count = 1;
				foreach (var param in method.TypeParameters) {
					this.currentType = "typeparam";
					curName = param.Name;
					tags["TypeParam"] = param.Name;
					switch (count) {
					case 1:
						tags["TypeParamNumber"] = "1st";
						break;
					case 2:
						tags["TypeParamNumber"] = "2nd";
						break;
					case 3:
						tags["TypeParamNumber"] = "3rd";
						break;
					default:
						tags["TypeParamNumber"] = count + "th";
						break;
					}
					count++;
					DocConfig.Instance.Rules.ForEach (r => r.Run (this, param));
				}
			}
			
//			ITypeDefinition type;
//			if (member is ITypeDefinition) {
//				type = (ITypeDefinition)member;
//			} else {
//				type = ((IMember)member).DeclaringTypeDefinition;
//			}
			
// TODO: Exceptions!
//			this.currentType = "exception";
//			foreach (var exception in visitor.Exceptions) {
//				var exceptionType = MonoDevelop.Refactoring.HelperMethods.ConvertToReturnType (exception);
//				
//				
//				curName = exceptionType.FullName;
//				tags["Exception"] = exceptionType.ToInvariantString ();
//				SplitWords (exceptionType, exceptionType.Name);
//				
//				if (type != null) {
//					IType resolvedType = type.GetProjectContent ().SearchType (type.CompilationUnit, type, type.Location, exceptionType);
//					string sentence = AmbienceService.GetDocumentationSummary (resolvedType);
//					if (! string.IsNullOrEmpty(sentence)) {
//						sentence = sentence.Trim ();
//						if (sentence.StartsWith ("<para>") && sentence.EndsWith ("</para>"))
//							sentence = sentence.Substring ("<para>".Length, sentence.Length - "<para>".Length - "</para>".Length).Trim ();
//						if (sentence.StartsWith ("Represents the error that occurs when"))
//							sentence = "Is thrown when" + sentence.Substring ("Represents the error that occurs when".Length);
//						if (!string.IsNullOrEmpty (sentence))
//							Set ("exception", curName, sentence);
//					}
//				}
//				
//				DocConfig.Instance.Rules.ForEach (r => r.Run (this));
//			}
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:78,代码来源:DocGenerator.cs

示例13: EvaluateCondition

		public bool EvaluateCondition (List<KeyValuePair<string, string>> conditions, ISymbol member)
		{
			foreach (var condition in conditions) {
				bool result = false;
				foreach (string val in condition.Value.Split (',')) {
					switch (condition.Key) {
					case "type":
						result |= val == currentType;
						break;
					case "modifier":
						if (val.ToUpperInvariant () == "STATIC"){
							result |= member.IsStatic;
						} else {
							try {
								var mod = (Accessibility)Enum.Parse (typeof(Accessibility), val);
								result |=  member.DeclaredAccessibility == mod;
							} catch (Exception) {
							}
						}
						break;
					case "paramCount":
						var parameters = member.GetParameters ();
						result |= Int32.Parse (val) == parameters.Length;
						break;
					case "parameter":
						parameters = member.GetParameters ();
						string[] par = val.Split(':');
						int idx = Int32.Parse (par[0]);
						string name = par[1];
						result |= idx < parameters.Length && name == parameters[idx].Name;
						break;
					case "returns":
						if (member is IParameterSymbol) {
							result |= val == ((IParameterSymbol)member).Type.ToString ();
							break;
						}

						result |= val == member.GetReturnType ().ToString ();
						break;
					case "name":
						var method = member as IMethodSymbol;
						if (method != null && method.MethodKind == MethodKind.UserDefinedOperator) {
							string op = GetOperator (method.Name);
							if (op != null) {
								result |= val == op;
								break;
							}
						}
							
						result |= val == GetName (member);
						break;
					case "endsWith":
						if (member == null)
							break;
						result |= GetName (member).EndsWith (val, StringComparison.Ordinal);
						break;
					case "startsWith":
						if (member == null)
							break;
						result |= GetName (member).StartsWith (val, StringComparison.Ordinal);
						break;
					case "startsWithWord":
						if (member == null)
							break;
						var name2 = SeparateWords (GetName (member));
						result |= name2.StartsWith (val + " ");
						break;
					case "wordCount":
						result |= Int32.Parse (val) == wordCount;
						break;
					default:
						throw new Exception ("unknown condition:" + condition.Key);
					}
				}
				if (!result)
					return false;
			}
			return true;
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:79,代码来源:DocGenerator.cs

示例14: CreateItemAsync

        private async Task<CompletionItem> CreateItemAsync(
            Workspace workspace, SemanticModel semanticModel, int textChangeSpanPosition, ISymbol symbol, SyntaxToken token, CancellationToken cancellationToken)
        {
            int tokenPosition = token.SpanStart;
            string symbolText = string.Empty;

            if (symbol is INamespaceOrTypeSymbol && token.IsKind(SyntaxKind.DotToken))
            {
                symbolText = symbol.Name.EscapeIdentifier();

                if (symbol.GetArity() > 0)
                {
                    symbolText += "{";
                    symbolText += string.Join(", ", ((INamedTypeSymbol)symbol).TypeParameters);
                    symbolText += "}";
                }
            }
            else
            {
                symbolText = symbol.ToMinimalDisplayString(semanticModel, tokenPosition, CrefFormat);
                var parameters = symbol.GetParameters().Select(p =>
                    {
                        var displayName = p.Type.ToMinimalDisplayString(semanticModel, tokenPosition);

                        if (p.RefKind == RefKind.Out)
                        {
                            return "out " + displayName;
                        }

                        if (p.RefKind == RefKind.Ref)
                        {
                            return "ref " + displayName;
                        }

                        return displayName;
                    });

                var parameterList = !symbol.IsIndexer() ? string.Format("({0})", string.Join(", ", parameters))
                                                        : string.Format("[{0}]", string.Join(", ", parameters));
                symbolText += parameterList;
            }

            var insertionText = symbolText
                .Replace('<', '{')
                .Replace('>', '}')
                .Replace("()", "");

            var text = await semanticModel.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
            return new CrefCompletionItem(
                workspace,
                completionProvider: this,
                displayText: insertionText,
                insertionText: insertionText,
                textSpan: GetTextChangeSpan(text, textChangeSpanPosition),
                descriptionFactory: CommonCompletionUtilities.CreateDescriptionFactory(workspace, semanticModel, tokenPosition, symbol),
                glyph: symbol.GetGlyph(),
                sortText: symbolText);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:58,代码来源:CrefCompletionProvider.cs


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