On Thu, Jan 15, 2009 at 7:28 PM, Keith <[email protected]> wrote: > var intq = assembly.MainModule.Import(typeof(int?)); > > var ntor = intq.Constructors[0]; > > Oops. I now see that this won't work because Import gives a TypeRef, > while Constructors needs a TypeDef. Sorry. > > But I do see the error; ReflectionHelper.ImportMethodBase, line 367, > gets parameters from the closed method. Hmm. There doesn't seem to be > an easy way to get the original declared (open) method from it. Lovely.
Actually from my tests it doesn't seem to get that far as it returns (at least here) in line 347 after calling GetMethodBaseSignature() at line 344. Anyway it does the same thing, gets the closed parameters from SR.MethodBase around line 276. I was looking SR.MethodBase and indeed seems quite tricky to find out that it is a closed method from a generic open method. I found that "IsGenericMethod" and "IsGenericMethodDefinition" are both false, seems strange. Also "ContainsGenericParameters" is false. As far I looked around I believe that the only way to find out if it is a closed method from an existing open method is: 1st) check if SR.MethodBase is a ConstructorInfo, as the constructors should always be opened. 2nd) check if the DeclaringType is a generic type; 3rd) do the hard work of creating the signature right. I didn't read the ECMA-335 yet and I'm still learning the Cecil source so sorry if I'm getting it wrong, this is what I understand so far. Augusto --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~---
