[Mono-dev] wrong generic method signature

Denis ERCHOFF d_erchoff at hotmail.com
Tue Jul 8 04:09:57 EDT 2008


Hi,

I would like to share with you a small modification in the mono C# compiler.

Initially the problem was :

    i write a simple generic method like this :

          public void test_generic_method<A>(int B)

    using the ms compiler + the VS object viewer, the signature appear 
in the format :
      
          test_generic_method<A>(int)

    using the mono compiler + the VS object viewer, the signature appear 
in the format :

           test_generic_method<A>() <--- where is the paranter signature 
part ?
          If i use the Luts Roeader's.Net Reflector, it crashed when i 
try to parse the class containing this method.


---> The mono .net framework is not installed in my computer. I use only 
a ms .net framework. So maybe the problem doesn't occur with the mono 
framework.


It seems that the MethodBuilder.SetParameters doesn't work as expected 
if you don't define parameters when calling the method 
TypeBuilder.DefineMethod.

So i tryed to change the mono c# compiler to have the expected signature :

In the Mono.CSharp.MethodOrOperator.DefineGenericMethod i removed all 
the generic related code :

protected bool DefineGenericMethod ()
        {
            if (!DoDefineBase ())
                return false;
            return true;
          }



And i rewrited the Mono.CSharp.MethodData.DefineMethodBuilder as :



        void DefineMethodBuilder (TypeContainer container, string 
method_name, Type[] ParameterTypes)
        {
            if (builder == null) {
                builder = container.TypeBuilder.DefineMethod (
                    method_name, flags, method.CallingConventions,
                    method.ReturnType, ParameterTypes);
#if GMCS_SOURCE
                if (GenericMethod != null)
                {
                    //MethodBuilder = 
Parent.TypeBuilder.DefineMethod(GetFullName(MemberName), flags);
                    GenericMethod.Define(MethodBuilder, null);
                }

                if (builder.Attributes != flags)
                {
                    try
                    {
                        if (methodbuilder_attrs_field == null)
                            methodbuilder_attrs_field = 
typeof(MethodBuilder).GetField("attrs", BindingFlags.NonPublic | 
BindingFlags.Instance);
                        methodbuilder_attrs_field.SetValue(builder, flags);
                    }
                    catch
                    {
                        Report.RuntimeMissingSupport(method.Location, 
"Generic method MethodAttributes");
                    }
                }
#endif

                return;
            }
}

Like this, all seems to be good ( event the   Luts Roeader's.Net 
Reflector ).

Tell me if something is wrong.

Denis.

P.s. : I attached a patch file to this email.
 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: wrong_generic_method_signature.patch
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080708/8b961747/attachment.pl 


More information about the Mono-devel-list mailing list