Hello 

After testing the cneptune library published 
here: https://github.com/Virtuoze/CNeptune

I made some tweaks to transform this (as seen in ILSpy):

     public class GenericClass<T1, T2>
    {
        public int Value
        {
            get;
            set;
        }

        public void MustReceiveMyself(GenericClass<T1, T2> 
anInstanceOfMyself)
        {
            anInstanceOfMyself.Value = 10;
            Console.WriteLine(anInstanceOfMyself.Value);
        }
    }

Into this (as seen in ILSpy):

public class GenericClass<T1, T2>
    {
        [CompilerGenerated, Serializable]
        internal static class <Neptune>
        {
            [CompilerGenerated, Serializable]
            public static class <Authentic>
            {
                public static int get_Value(GenericClass<!0, !1> @this)
                {
                    return @this.<Value>k__BackingField;
                }

                public static void set_Value(GenericClass<!0, !1> @this, int 
value)
                {
                    @this.<Value>k__BackingField = value;
                }

                public static void MustReceiveMyself(GenericClass<!0, !1> 
@this, GenericClass<!0, !1> anInstanceOfMyself)
                {
                    anInstanceOfMyself.Value = 10;
                    Console.WriteLine(anInstanceOfMyself.Value);
                }

                public static void <Constructor>(GenericClass<!0, !1> @this)
                {
                    @this..ctor();
                }
            }

            [CompilerGenerated, Serializable]
            public static class <Intermediate>
            {
                [CompilerGenerated, Serializable]
                public static class <get_Value>
                {
                    [DebuggerBrowsable(DebuggerBrowsableState.Never), 
CompilerGenerated]
                    public static IntPtr <Pointer> = MethodBase.
GetMethodFromHandle(methodof(GenericClass.<Neptune>.<Authentic>.get_Value
(GenericClass<!0, !1>)).MethodHandle, typeof
(GenericClass.<Neptune>.<Authentic>).TypeHandle).MethodHandle.
GetFunctionPointer();
                }

                [CompilerGenerated, Serializable]
                public static class <set_Value>
                {
                    [DebuggerBrowsable(DebuggerBrowsableState.Never), 
CompilerGenerated]
                    public static IntPtr <Pointer> = MethodBase.
GetMethodFromHandle(methodof(GenericClass.<Neptune>.<Authentic>.set_Value
(GenericClass<!0, !1>, int)).MethodHandle, typeof
(GenericClass.<Neptune>.<Authentic>).TypeHandle).MethodHandle.
GetFunctionPointer();
                }

                [CompilerGenerated, Serializable]
                public static class <MustReceiveMyself>
                {
                    [DebuggerBrowsable(DebuggerBrowsableState.Never), 
CompilerGenerated]
                    public static IntPtr <Pointer> = MethodBase.
GetMethodFromHandle(methodof(GenericClass.<Neptune>.<Authentic>.
MustReceiveMyself(GenericClass<!0, !1>, GenericClass<!0, !1>)).MethodHandle, 
typeof(GenericClass.<Neptune>.<Authentic>).TypeHandle).MethodHandle.
GetFunctionPointer();
                }

                [CompilerGenerated, Serializable]
                public static class <<Constructor>>
                {
                    [DebuggerBrowsable(DebuggerBrowsableState.Never), 
CompilerGenerated]
                    public static IntPtr <Pointer> = MethodBase.
GetMethodFromHandle(methodof
(GenericClass.<Neptune>.<Authentic>.<Constructor>(GenericClass<!0, 
!1>)).MethodHandle, 
typeof(GenericClass.<Neptune>.<Authentic>).TypeHandle).MethodHandle.
GetFunctionPointer();
                }
            }
        }

        public int Value
        {
            [CompilerGenerated]
            get
            {
                return calli(System.Int32(CNeptune.Test.Target.GenericClass`
2<T1,T2>), this, 
GenericClass.<Neptune>.<Intermediate>.<get_Value>.<Pointer>);
            }
            [CompilerGenerated]
            set
            {
                
calli(System.Void(CNeptune.Test.Target.GenericClass`2<T1,T2>,System.Int32), 
this, value, GenericClass.<Neptune>.<Intermediate>.<set_Value>.<Pointer>);
            }
        }

        public void MustReceiveMyself(GenericClass<T1, T2> 
anInstanceOfMyself)
        {
            calli(System.Void(CNeptune.Test.Target.GenericClass`2
<T1,T2>,CNeptune.Test.Target.GenericClass`2<T1,T2>), this, 
anInstanceOfMyself, 
GenericClass.<Neptune>.<Intermediate>.<MustReceiveMyself>.<Pointer>);
        }

        public GenericClass()
        {
            calli(System.Void(CNeptune.Test.Target.GenericClass`2<T1,T2>), 
this, GenericClass.<Neptune>.<Intermediate>.<<Constructor>>.<Pointer>);
        }
    }

To arrive at the above, I added these lines to the method of Program  
MethodDefinition Authentic(this MethodDefinition method)

if (!method.IsStatic)
            {
                var t = method.DeclaringType;
                var theType = t.HasGenericParameters
                    ? 
(TypeReference)t.MakeGenericType(t.GetElementType().GenericParameters)
                    : t;
                _method.Parameters.Add(new ParameterDefinition("this", 
ParameterAttributes.None, theType));
            }

Without the lines above modification, any reference to GenericClass<!0,!1> 
just becomes GenericClass, and references to GenericClass`2<T1,T2> just 
become GenericClass`2.

I cannot find a way to convert the !0 and !1 to the correct type arguments 
T1 and T2. 

If I try to instantiate the above GenericClass, it results in a 
BadImageFormatException

Any hint or help you can give me to make this transformation work will be 
greatly appreciated.

Best Regards

-- 
-- 
--
mono-cecil
--- 
You received this message because you are subscribed to the Google Groups 
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to