Hi JB,
well, did some more tests, and below is what I have now. As far as I
understand, in my cases I CANNOT call MakeGenericMethod, because my
method is actually a NON generic method of a Generic type, just
expecting the Generic type parameter as the argument. Here is where
the problem lies.
The code so far:
_LINQ = _Resolver.Resolve(_AssemblyName);//is the name of
System.Data.Linq
var _EntityRefClassLocal = _LINQ.MainModule.Types.Where(x => x.Name ==
"EntityRef`1").FirstOrDefault();
var _EntityRefClass =
assemblyToEnhance.MainModule.Import(_EntityRefClassLocal);
var _entityRefClassSetEntityMethod =
EntityRefClass.Resolve().GetMethod("set_Entity");
var _EntityRefGenericMethod =
entityRefClassSetEntityMethod.MakeGeneric(_Field.FieldType); //
FieldType is OL2S.TestClassesIntercepted.Party
// method set_Entity is EntityRef<T>::set_Entity(T) NOT !!
EntityRef<T>::set_Entity<T>(someargument)
// so GenericParameters.Count is 0, therefore I cannot call
MakeGenericMethod
// but there is an ARGUMENT which is currently nothing, so I tried to
set this
_EntityRefGenericMethod.Parameters[0] = new
ParameterDefinition(_Field.FieldType); //FieldType is
OL2S.TestClassesIntercepted.Party
//Import it
MethodReference _MethodReference =
aMSILStream.DeclaringType.Module.Import(_EntityRefGenericMethod);
//and call the method
_NewInstruction = Instruction.Create(OpCodes.Call, _MethodReference);
// MethodReference to string no shows this as
instance void valuetype
[System.Data.Linq]System.Data.Linq.EntityRef`1<OL2S.TestClassesIntercepted.Party>::set_Entity(OL2S.TestClassesIntercepted.Party)
but it should be
instance void valuetype
[System.Data.Linq]System.Data.Linq.EntityRef`1<OL2S.TestClassesIntercepted.Party>::set_Entity(!
0)
and ILDASM shows:
call instance class
[TestClassesIntercepted]OL2S.TestClassesIntercepted.Party valuetype
[System.Data.Linq]System.Data.Linq.EntityRef`1<class
[TestClassesIntercepted]OL2S.TestClassesIntercepted.Party>::set_Entity<[1]>(
[SIGNATURE
ENDED PREMATURELY])
It suddenly seems to have a return type, although the MethodReference
shows systmem.void.
Thanks for the quick help, let me know if you need anything more.
Joe Robe
On Nov 18, 10:08 am, Jb Evain <[email protected]> wrote:
> Hey,
>
> On Thu, Nov 18, 2010 at 3:56 PM, joer <[email protected]> wrote:
> > What am I doing wrong ?
>
> It's hard to tell without seeing the actual source.
>
> Jb
--
--
mono-cecil