[Mono-bugs] [Bug 332204] New: Cecil duplicates generics memberref

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Oct 9 10:12:27 EDT 2007


https://bugzilla.novell.com/show_bug.cgi?id=332204

           Summary: Cecil duplicates generics memberref
           Product: Mono: Class Libraries
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: ASSIGNED
          Severity: Normal
          Priority: P5 - None
         Component: Cecil
        AssignedTo: jbevain at novell.com
        ReportedBy: jbevain at novell.com
         QAContact: mono-bugs at ximian.com
          Found By: Third Party Developer/Partner


Test case:

using System;
using System.Text;
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace ConsoleApplication23
{
   class Program
   {
       static AssemblyDefinition asm;
       static ModuleDefinition mod;
       static AssemblyNameReference mscorlib;
       static TypeReference type_void;
       static TypeReference type_object;
       static TypeReference type_ienumerablegen;
       static TypeReference type_ienumeratorgen;

       static void Main(string[] args)
       {
           asm = AssemblyFactory.DefineAssembly("test", "test.dll",
TargetRuntime.NET_2_0, AssemblyKind.Dll);
           mod = asm.MainModule;

           mscorlib = new AssemblyNameReference("mscorlib", "", new
Version(2,0,0,0));
           mscorlib.PublicKeyToken = new byte[] { 0xB7, 0x7A, 0x5C, 0x56, 0x19,
0x34, 0xE0, 0x89 };

           mod.AssemblyReferences.Add(mscorlib);
           type_void = new TypeReference("Void", "System", mscorlib, true);
           type_ienumerablegen = new TypeReference("IEnumerable`1",
"System.Collections.Generic", mscorlib, false);
           type_ienumerablegen.GenericParameters.Add(new GenericParameter("T",
type_ienumerablegen));

           type_ienumeratorgen = new TypeReference("IEnumerator`1",
"System.Collections.Generic", mscorlib, false);
           type_ienumeratorgen.GenericParameters.Add(new GenericParameter("T",
type_ienumeratorgen));
           type_object = new TypeReference("Object", "System", mscorlib,
false);

           mod.TypeReferences.Add(type_void);
           mod.TypeReferences.Add(type_ienumerablegen);
           mod.TypeReferences.Add(type_object);
           mod.TypeReferences.Add(type_ienumeratorgen);

           AddClass("Test1`1");
           AddClass("Test2`1");

           AssemblyFactory.SaveAssembly(asm, "c:\\test.dll");
       }

       private static void AddClass(string name)
       {
           // Create a new type
           TypeDefinition type = new TypeDefinition(name, "Mine",
TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public,
type_object);

           mod.Types.Add(type);
           type.GenericParameters.Add(new GenericParameter("test", type));

           //add a generic parameter
           MethodDefinition meth = new MethodDefinition("Test",
MethodAttributes.Static | MethodAttributes.Public, type_void);

           GenericInstanceType methpar = new
GenericInstanceType(type_ienumerablegen);
           methpar.GenericArguments.Add(type.GenericParameters[0]);

           // create a IEnumerable`1<Test>
           meth.Parameters.Add(new ParameterDefinition("testpar", 0,
ParameterAttributes.None, methpar));

           GenericInstanceType enumeratorgen = new
GenericInstanceType(type_ienumeratorgen);
          
enumeratorgen.GenericArguments.Add(type_ienumeratorgen.GenericParameters[0]);
// result of the call

           MethodReference meth_getenumerable = new
MethodReference("GetEnumerator", methpar, enumeratorgen, true, false,
MethodCallingConvention.Default);

           mod.MemberReferences.Add(meth_getenumerable);

           CilWorker worker = meth.Body.CilWorker;
           worker.Emit(OpCodes.Ldarg_0);
           worker.Emit(OpCodes.Callvirt, meth_getenumerable);
           worker.Emit(OpCodes.Pop);
           worker.Emit(OpCodes.Ret);
           meth.Body.MaxStack = 1;

           type.Methods.Add(meth);
       }
   }
}


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list