Tank you Jb Evain, with this I almost managed to implement it, but I
come across another thing that confuses me:

Consider this hierarchy:
class StrDict<T> : Dictionary<string, T>
class MyDictionary : StrDict<double>

and following code:
            var strDictRef = myDictionaryRef.Resolve().BaseType;
            var strDictPars =
((GenericInstanceType)strDictRef).ElementType.GenericParameters;
            var dictRef = strDictRef.Resolve().BaseType;    // this is
reference to Dictionary<string, T>
            var dictPars =
((GenericInstanceType)dictRef).ElementType.GenericParameters;

strDictPars contain, as expected, a generic parameter with name 'T',
so I can do the mapping T -> double.
So far so good. However, dictPars contain generic parameters with
names '!0' and '!1' instead of TKey and TValue,
so I cannot map generic arguments of the Dictionary<string, T>
reference, which are string and double (got from T -> double),
to IDictionary<TKey, TValue>. Is this by design, or a bug? How can I
get correct names of the
generic parameters in this case? (Btw. I am using the latest NuGet
package and .NET 4.0).

Thank you for your patience Jb O:-)

On 30 dub, 11:51, Jb Evain <jbev...@gmail.com> wrote:
> On Sat, Apr 30, 2011 at 11:46 AM, Steves <m...@stevesindelar.cz> wrote:
> > I am missing one thing to implement this: when I have a reference to
> > say List<int>, I can get System.Int32 through
> > ((GenericInstanceType)myReference).GenericArguments. How can I get the
> > information that System.Int32 is actually generic parameter "T"? In
> > debugger I can see that myReference has property
> > Mono.Cecil.IGenericContext.Type, which contains the GenericParameter
> > "T", but the Mono.Cecil.IGenericContext interface is internal.
>
> You can write:
>
> var list_int32_ref = (GenericInstanceType) myReference;
> var int32_ref = genericInstance.GenericArguments [0];
> var list_ref = genericInstance.ElementType;
> var t = list_ref.GenericParameters [0];
>
> Jb

-- 
--
mono-cecil

Reply via email to