Hi, I'm afraid Cecil doesn't have a good PCL story right now.
I suspect the issue is that when you call Resolve(), Cecil's default resolver will pick the .net 4.0 assembly, so you end up having wrong references. You could alleviate this by writing your own PCL profile understanding assembly resolver. Jb On Wed, Aug 20, 2014 at 10:57 PM, <[email protected]> wrote: > So I'm trying to inject a call to 'Nullable<DateTime>.HasValue' in an > assembly that is a PCL. > > Code so far: > > var field = ... // this is the Nullable<DateTime> field > var get_HasValue = field.FieldType.Resolve().Methods.First(i=>i.Name == > "get_HasValue") > ... > instructions.Add(Instruction.Create(OpCodes.Call, get_HasValue)); > ... > > > After running this, it says I need to import the method 'get_HasValue' into > the assembly that I'm writing. Shouldn't that method already be in my > assembly since it's actually referenced at compile time? > > Either way, I tried this: > > ... > var get_HasValue = > myAssembly.MainModule.Import(field.FieldType.Resolve().Methods.First(i=>i.Name > == "get_HasValue")) > ... > > And it works in one runtime but not another (that is, it works in .net 4.5 > but not winphone 8). > > > Also, the IL shows: > call instance bool [mscorlib]System.Nullable`1::get_HasValue() > > when it should be: > > call instance bool valuetype > [System.Runtime]System.Nullable`1<valuetype > [System.Runtime]System.DateTime>::get_HasValue() > > > Any tips on what I'm doing wrong? I guess, in general, I want to be able to > resolve System types to inject. I can inject types that are defined in my > assembly just fine. > > Thanks. > > -- > -- > -- > 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. -- -- -- 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.
