I'm thinking that a (albeit more laborious) more explicit API that forces
that kind of thing would make for a much better learning curve (i.e. having
OpCode-derived classes and overloads with the specific arguments expected by
them?)
fixed that particular issue now.

how do I know if a ParameterDefinition is byref ? IsOut or IsRetval don't
work. Should I just look for a trailing "&" on the type name? :|

On Mon, Jan 5, 2009 at 5:57 PM, Jb Evain <[email protected]> wrote:

>
> On 1/5/09, Daniel Cazzulino <[email protected]> wrote:
> > fixed!
>
> Cool!
>
> > [Fact]
> > public void CecilRepro()
> > {
> >  var asm =
> > AssemblyFactory.GetAssembly(this.GetType().Assembly.Location);
> >  var listOfObject =
> > asm.MainModule.Import(typeof(List<object>));
> >  var method = asm.MainModule.Types.Cast<TypeDefinition>()
> >  .Where(t => t.FullName == this.GetType().FullName)
> >  .Single()
> >  .Methods.Cast<MethodDefinition>()
> >  .Where(m => m.Name == "CecilRepro")
> >  .Single();
> >
> >  var il = method.Body.CilWorker;
> >  var argsVar = new VariableDefinition(listOfObject);
> >  method.Body.Variables.Add(argsVar);
> >  il.InsertBefore(method.Body.Instructions[0],
> >  il.Create(OpCodes.Newobj, listOfObject));
> > }
> >
> > fails with:
> >
> > TestCase
> > 'Moq.Tests.Instrumentation.InstrumentationFixture.FailsToImport'
> > failed: System.ArgumentException : opcode
> >  at Mono.Cecil.Cil.CilWorker.Create(OpCode opcode,
> > TypeReference type)
> > D:\Code\moq\UnitTests\Instrumentation\InstrumentationFixture.cs(49,0):
> > at
> > Moq.Tests.Instrumentation.InstrumentationFixture.FailsToImport()
>
> That's because newobj wants a MethodReference that should be the
> actual constructor, not the type.
>
> What if you pass the result of the Import of the constructor of
> List<object> to newobj?
>
> --
> Jb Evain  <[email protected]>
>
> >
>


-- 
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1
425.329.3471

--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to