Bug 1132 - Intellisense for instantiating delegates is incorrect
Summary: Intellisense for instantiating delegates is incorrect
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: unspecified
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Mike Krüger
Depends on:
Reported: 2011-09-29 08:15 UTC by Dermot
Modified: 2012-01-20 04:18 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Dermot 2011-09-29 08:15:12 UTC
Intellisense for instantiating delegates is incorrect.


public delegate void TestDelegate(string x, int y);

public void TestMethod(string x,int y)

public void SetupDelegate()
    TestDelegate myDelegate = new TestDelegate(***** PROBLEM ONE HERE *****);
    myDelegate.BeginInvoke.... ** PROBLEM TWO HERE *****


Problem One:
Intellisense suggests, in the above case, to insert (string x, int y) rather than suggesting the target method (TestMethod())

Problem Two:

after typing myDelegate.  the intellisense only sees it as an object, not as a delegate. If I want to call BeginInvoke, i have to ensure my code is correct, because as far as intellisense is concerned, myDelegate is just an object.

Using latest stable releases of all softwares (Mono, Monotouch, Monodevelop) as of today.
Comment 1 Dermot 2011-10-05 03:20:47 UTC
This probably fits in the same bug report:

When creating an anonymous method delegate

 eg: thisButton.TouchUpInside+= new delegate(EventArgs e)
    //Here, e does not appear in intellisense, however typing e , then hitting escape to avoid intellisense  
   // auto-complete and then typing a dot causes intellisense to list the members of e
   //Note, the compiler itself is fine, this is just an intellisense issue.

Comment 2 himajin100000 2011-11-17 06:23:26 UTC
On my PC(Windows Vista), as comment 1 say , anonymous method parameter not displayed in completion list with following code.

using System;
using System.Diagnostics;
using System.Collections.Generic;

namespace Namespace
	class MainClass
		public static void Main (string[] args)
			int a;
			int b;
			List<int> x = new List<int>();
			x.ForEach (delegate(int p){System.Console.WriteLine (/* check whether parameter p is in completion list */ );});


ICSharpCode.OldNRefactory.Ast.CompilationUnit.AddChild(INode childNode) 

public override void AddChild(INode childNode){
	if (childNode != null) {
		/* himajin100000's Modification Start */				
		System.IO.StreamWriter swA = new System.IO.StreamWriter(new System.IO.FileStream("D:\\test\\D.txt",System.IO.FileMode.Append ));
		swA.WriteLine("CompilationUnit AddChild:" + childNode.ToString ());
		/* himajin100000's Modification End*/

		INode parent = (INode)blockStack.Peek();
		childNode.Parent = parent;



public override object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data)
	/* himajin100000 Added some code to see what happened */
	System.IO.StreamWriter sw4 = new System.IO.StreamWriter(new System.IO.FileStream("D:\\test\\D.txt",System.IO.FileMode.Append ));
	sw4.WriteLine("Route LookupTableVisitor::VisitAnonymousMethodExpression");
	foreach (ParameterDeclarationExpression p in anonymousMethodExpression.Parameters) {
		sw4.WriteLine("Variable:" + p.ParameterName);

		AddVariable(p.TypeReference, p.ParameterName,
			            anonymousMethodExpression.StartLocation, anonymousMethodExpression.EndLocation,
			            false, false, null, null, false, anonymousMethodExpression.EndLocation);

	return base.VisitAnonymousMethodExpression(anonymousMethodExpression, data);

seemed to understand  that there is an AnonymousMethodExpression who has one int parameter p, from what I understand from the written file.

but when I followed the code in MonoDevelop.CSharp.Resolver.NRefactoryResolver.cs,
I found that it seemed to meet following conditions,meaning the caret is now outside of where the identifier p can exist), and without adding parameters to CSharpTextEditorCompletion.CompletionDataCollector col,
MonoDevelop continues the loop.


if (varStartPos > this.resolvePosition || (!v.EndPos.IsEmpty && varEndPos < this.resolvePosition))

I'm not yet understanding the following lines, but I hope my comment helps.

DomLocation varStartPos = new DomLocation (lookupVariableLine + v.InListPosition.Line, v.InListPosition.Column - 1);
DomLocation varEndPos   = new DomLocation (lookupVariableLine + v.EndPos.Line, v.EndPos.Column - 1);
Comment 3 Mike Krüger 2012-01-20 04:18:29 UTC
Works in newresolver branch.

btw. problem 1 is not really a problem, because the lambda is valid there, if you type the first letter "T" TestMethod should be selected.