Parameters in Indexer Properties

by Miguel de Icaza

C# allows an arbitrary number of parameters (similar to varargs in C) in indexer properties. This looks like this:

   class Vector {
	 public object this [params object [] items]
	 {
	 	get { ... }
        	set { ... }
         }
    }

    // ...

    Vector v = new Vector ();

    v [1, 2, 3] = 10;
	

This is one of the parts of the spec that I did not find on the first pass of writing the compiler, so the internal design of the compiler did not allow for this particular usage. Not many applications depended on it, but there have been a few.

The problem was that the compiler had a flag describing whether a method's last parameter was a "params" (setters and getters are treated as methods). This works for the getter method, but the problem is that the setter method has a params in the middle, the above would turn into:

	object set_Item (object [] items, object value) 
	

Today Marek Safar submitted a fix to this long standing bug. Although the bug was filed by a third party a year ago, it was on my personal compiler TODO list for at least three years.

This fix will be on Mono 1.2.3 or it's available on SVN on r69571.

Posted on 16 Dec 2006