[Mono-dev] typemanager patch to get correct indexer signature

Marek Safar marek.safar at gmail.com
Mon Nov 14 07:30:23 EST 2005


Hello Eno,
> I have a patch for typemanager.cs to fix the signature of an indexer
> to report (i.e. GetSignatureForError()). Currently it does not
> differentiate things like "this[int]" and "this[string]". Actually
> it did not detect indexer getter methods (since the existing code
> expects more than one parameter).
>
> This rarely matters but I have a testable testcase with related to
> /doc feature (actually reported in bug #76685).
>
> Anyone please review for this patch?
>   
As soon as all tests pass, please commit.

Marek

> ------------------------------------------------------------------------
>
> // cs0419-2.cs: Ambiguous reference in cref attribute `A.this'. Assuming `Test.A.this[string]' but other overloads including `Test.A.this[int]' have also matched
> // Line: 7
> // Compiler options: -doc:dummy.xml -warnaserror
> using System.Collections;
>
> /// <summary>
> ///   <para><see cref="IDictionary.this[object]" /></para>
> ///   <para><see cref="A.this" /></para>
> ///   <para><see cref="B.this" /></para>
> /// </summary>
> public class Test
> {
>   static void Main()
>   {
>   }
>
>   private class A
>   {
>     public object this[int index] {
>       get { return null; }
>     }
>
>     public object this[string index] {
>       get { return null; }
>     }
>   }
>
>   private class B
>   {
>     public object this[int index] {
>       get { return null; }
>     }
>   }
> }
>
>   
> ------------------------------------------------------------------------
>
> Index: typemanager.cs
> ===================================================================
> --- typemanager.cs	(revision 52958)
> +++ typemanager.cs	(working copy)
> @@ -587,6 +587,14 @@
>  	/// </summary>
>  	static public string GetFullNameSignature (MemberInfo mi)
>  	{
> +		PropertyInfo pi = mi as PropertyInfo;
> +		if (pi != null) {
> +			MethodBase pmi = pi.GetGetMethod ();
> +			if (pmi == null)
> +				pmi = pi.GetSetMethod ();
> +			if (GetParameterData (pmi).Count > 0)
> +				mi = pmi;
> +		}
>  		return (mi is MethodBase)
>  			? CSharpSignature (mi as MethodBase) 
>  			: CSharpName (mi.DeclaringType) + '.' + mi.Name;
> @@ -629,14 +637,17 @@
>  
>  		// Is indexer
>  		if (mb.IsSpecialName && !mb.IsConstructor) {
> -			if (iparams.Count > 1) {
> +			if (iparams.Count > (mb.Name.StartsWith ("get_") ? 0 : 1)) {
>  				sig.Append ("this[");
>  				if (show_accessor) {
>  					sig.Append (parameters.Substring (1, parameters.Length - 2));
>  				}
>  				else {
>  					int before_ret_val = parameters.LastIndexOf (',');
> -					sig.Append (parameters.Substring (1, before_ret_val - 1));
> +					if (before_ret_val < 0)
> +						sig.Append (parameters.Substring (1, parameters.Length - 2));
> +					else
> +						sig.Append (parameters.Substring (1, before_ret_val - 1));
>  				}
>  				sig.Append (']');
>  			} else {
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>   




More information about the Mono-devel-list mailing list