protected override SyntaxToken CreateMethodName() { // change this to more smarter one. var semanticModel = this.SemanticDocument.SemanticModel; var nameGenerator = new UniqueNameGenerator(semanticModel); var scope = this.CSharpSelectionResult.GetContainingScope(); return SyntaxFactory.Identifier(nameGenerator.CreateUniqueMethodName(scope, "NewMethod")); }
protected override SyntaxToken CreateMethodName() { // change this to more smarter one. var semanticModel = this.SemanticDocument.SemanticModel; var nameGenerator = new UniqueNameGenerator(semanticModel); var scope = this.CSharpSelectionResult.GetContainingScope(); return(SyntaxFactory.Identifier(nameGenerator.CreateUniqueMethodName(scope, "NewMethod"))); }
protected override SyntaxToken CreateMethodName() { var methodName = "NewMethod"; var containingScope = this.CSharpSelectionResult.GetContainingScope(); methodName = GetMethodNameBasedOnExpression(methodName, containingScope); var semanticModel = this.SemanticDocument.SemanticModel; var nameGenerator = new UniqueNameGenerator(semanticModel); return SyntaxFactory.Identifier(nameGenerator.CreateUniqueMethodName(containingScope, methodName)); }
protected override SyntaxToken CreateMethodName() { var methodName = "NewMethod"; var containingScope = this.CSharpSelectionResult.GetContainingScope(); methodName = GetMethodNameBasedOnExpression(methodName, containingScope); var semanticModel = this.SemanticDocument.SemanticModel; var nameGenerator = new UniqueNameGenerator(semanticModel); return(SyntaxFactory.Identifier(nameGenerator.CreateUniqueMethodName(containingScope, methodName))); }
void AddDelegateHandlers (List<CompletionData> completionList, SyntaxNode parent, SemanticModel semanticModel, CompletionEngine engine, CompletionResult result, ITypeSymbol delegateType, int position, string optDelegateName, CancellationToken cancellationToken) { var delegateMethod = delegateType.GetDelegateInvokeMethod (); result.PossibleDelegates.Add (delegateMethod); var thisLineIndent = ""; string EolMarker = "\n"; bool addSemicolon = true; bool addDefault = true; string delegateEndString = EolMarker + thisLineIndent + "}" + (addSemicolon ? ";" : ""); //bool containsDelegateData = completionList.Result.Any(d => d.DisplayText.StartsWith("delegate(")); CompletionData item; if (addDefault) { item = engine.Factory.CreateAnonymousMethod ( this, "delegate", "Creates anonymous delegate.", "delegate {" + EolMarker + thisLineIndent, delegateEndString ); if (!completionList.Any (i => i.DisplayText == item.DisplayText)) completionList.Add (item); //if (LanguageVersion.Major >= 5) item = engine.Factory.CreateAnonymousMethod ( this, "async delegate", "Creates anonymous async delegate.", "async delegate {" + EolMarker + thisLineIndent, delegateEndString ); if (!completionList.Any (i => i.DisplayText == item.DisplayText)) completionList.Add (item); } var sb = new StringBuilder ("("); var sbWithoutTypes = new StringBuilder ("("); for (int k = 0; k < delegateMethod.Parameters.Length; k++) { if (k > 0) { sb.Append (", "); sbWithoutTypes.Append (", "); } sb.Append (RoslynCompletionData.SafeMinimalDisplayString (delegateMethod.Parameters [k], semanticModel, position, overrideNameFormat)); sbWithoutTypes.Append (delegateMethod.Parameters [k].Name); } sb.Append (")"); sbWithoutTypes.Append (")"); var signature = sb.ToString () .Replace (", params ", ", ") .Replace ("(params ", "("); if (completionList.All (data => data.DisplayText != signature)) { item = engine.Factory.CreateAnonymousMethod ( this, signature + " =>", "Creates typed lambda expression.", signature + " => ", (addSemicolon ? ";" : "") ); if (!completionList.Any (i => i.DisplayText == item.DisplayText)) completionList.Add (item); // if (LanguageVersion.Major >= 5) { item = engine.Factory.CreateAnonymousMethod ( this, "async " + signature + " =>", "Creates typed async lambda expression.", "async " + signature + " => ", (addSemicolon ? ";" : "") ); if (!completionList.Any (i => i.DisplayText == item.DisplayText)) completionList.Add (item); var signatureWithoutTypes = sbWithoutTypes.ToString (); if (!delegateMethod.Parameters.Any (p => p.RefKind != RefKind.None) && completionList.All (data => data.DisplayText != signatureWithoutTypes)) { item = engine.Factory.CreateAnonymousMethod ( this, signatureWithoutTypes + " =>", "Creates typed lambda expression.", signatureWithoutTypes + " => ", (addSemicolon ? ";" : "") ); if (!completionList.Any (i => i.DisplayText == item.DisplayText)) completionList.Add (item); //if (LanguageVersion.Major >= 5) { item = engine.Factory.CreateAnonymousMethod ( this, "async " + signatureWithoutTypes + " =>", "Creates typed async lambda expression.", "async " + signatureWithoutTypes + " => ", (addSemicolon ? ";" : "") ); if (!completionList.Any (i => i.DisplayText == item.DisplayText)) completionList.Add (item); //} } } string varName = optDelegateName ?? "Handle" + delegateType.Name; var curType = semanticModel.GetEnclosingSymbol<INamedTypeSymbol> (position, cancellationToken); var uniqueName = new UniqueNameGenerator (semanticModel).CreateUniqueMethodName (parent, varName); item = engine.Factory.CreateNewMethodDelegate (this, delegateType, uniqueName, curType); if (!completionList.Any (i => i.DisplayText == item.DisplayText)) completionList.Add (item); }