good to know Import is for that :)there's no overload to import an Assembly
(as an AssemblyReference) though...
Converted all my calls to that now.
The following is failing, however :(
var addMethod = typeof(List<object>).GetMethod("Add");
Assert.NotNull(addMethod);
var addToList = asm.MainModule.Import(addMethod);
TestCase 'Moq.Tests.Instrumentation.InstrumentationFixture.InstrumentsClass'
failed: System.ArgumentOutOfRangeException : Index was out of range. Must be
non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.CollectionBase.System.Collections.IList.get_Item(Int32
index)
at Mono.Cecil.GenericParameterCollection.get_Item(Int32 index)
at Mono.Cecil.ReflectionHelper.GetGenericParameter(Type t, ImportContext
context)
at Mono.Cecil.ReflectionHelper.ImportSystemType(Type t, ImportContext
context)
at Mono.Cecil.ReflectionHelper.ImportMethodBase(MethodBase mb, Type retType,
ImportContext context)
at Mono.Cecil.ModuleDefinition.Import(MethodBase meth)
D:\Code\moq\UnitTests\Instrumentation\InstrumentationFixture.cs(47,0): at
Moq.Tests.Instrumentation.InstrumentationFixture.InstrumentsClass()
On Mon, Jan 5, 2009 at 11:23 AM, Jb Evain <[email protected]> wrote:
>
> Hey Daniel,
>
> On 1/5/09, Daniel Cazzulino <[email protected]> wrote:
> > var asm =
> > AssemblyFactory.GetAssembly(this.GetType().Assembly.Location);
> > // for some typedefinitions in that assembly, for all its methods:
> > var objectRef =
> > asm.MainModule.TypeReferences.Add(typeof(object));
> > var ins = il.Create(OpCodes.Newobj, objectRef);
>
> Aren't your extensions methods duplicating the Import code?
>
> I mean, you can do:
>
> var type_obj = module.Import (typeof (object));
>
> Does that work for you?
>
> --
> Jb Evain <[email protected]>
>
> >
>
--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1
425.329.3471
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---