+2007-09-09 Jb Evain <jbevain@novell.com>
+
+ * Mono.Cecil/GenericContext.cs
+ Mono.Cecil/ReflectionReader.cs
+ Mono.Cecil/DefaultImporter.cs:
+ Better handling of generic instances of references, where
+ the number of generic parameters is not known.
+
2007-09-06 Jb Evain <jbevain@novell.com>
* Mono.Cecil/MethodDefinition: add Is** methods for MethodImplAttributes.
else if (t is GenericInstanceType) {
GenericInstanceType git = t as GenericInstanceType;
GenericInstanceType genElemType = new GenericInstanceType (elementType);
+
+ context.GenericContext.CheckProvider (genElemType.GetOriginalType (), git.GenericArguments.Count);
foreach (TypeReference arg in git.GenericArguments)
genElemType.GenericArguments.Add (ImportTypeReference (arg, context));
GenericInstanceMethod ngim = new GenericInstanceMethod (
ImportMethodReference (gim.ElementMethod, context));
+ context.GenericContext.CheckProvider (ngim.GetOriginalMethod (), gim.GenericArguments.Count);
foreach (TypeReference arg in gim.GenericArguments)
ngim.GenericArguments.Add (ImportTypeReference (arg, context));
TypeReference m_type;
MethodReference m_method;
- bool m_allowCreation;
public TypeReference Type {
get { return m_type; }
}
public bool AllowCreation {
- get { return m_allowCreation; }
- set { m_allowCreation = value; }
+ get { return m_type != null && m_type.GetType () == typeof (TypeReference); }
}
public bool Null {
}
}
+ internal void CheckProvider (IGenericParameterProvider provider, int count)
+ {
+ if (!AllowCreation)
+ return;
+
+ for (int i = provider.GenericParameters.Count; i < count; i++)
+ provider.GenericParameters.Add (new GenericParameter (i, provider));
+ }
+
public GenericContext Clone ()
{
GenericContext ctx = new GenericContext ();
ct = (ct as GenericInstanceType).ElementType;
nc.Type = ct;
- nc.AllowCreation = ct.GetType () == typeof (TypeReference);
}
if (sig is FieldSig) {
throw new ReflectionException ("Unknown method type for method spec");
gim = new GenericInstanceMethod (meth);
+ context.CheckProvider (meth, sig.Signature.Arity);
foreach (GenericArg arg in sig.Signature.Types)
gim.GenericArguments.Add (GetGenericArg (arg, context));
return fnptr;
case ElementType.Var:
VAR var = t as VAR;
- if (context.AllowCreation)
- CheckGenericParameters (context, var);
+ context.CheckProvider (context.Type, var.Index + 1);
if (context.Type is GenericInstanceType)
return (context.Type as GenericInstanceType).GenericArguments [var.Index];
return context.Type.GenericParameters [var.Index];
case ElementType.MVar:
MVAR mvar = t as MVAR;
+ context.CheckProvider (context.Method, mvar.Index + 1);
+
if (context.Method is GenericInstanceMethod)
return (context.Method as GenericInstanceMethod).GenericArguments [mvar.Index];
else
GENERICINST ginst = t as GENERICINST;
GenericInstanceType instance = new GenericInstanceType (GetTypeDefOrRef (ginst.Type, context));
instance.IsValueType = ginst.ValueType;
+ context.CheckProvider (instance.GetOriginalType (), ginst.Signature.Arity);
for (int i = 0; i < ginst.Signature.Arity; i++)
instance.GenericArguments.Add (GetGenericArg (
return type;
}
- static void CheckGenericParameters (GenericContext context, VAR v)
- {
- for (int i = context.Type.GenericParameters.Count; i <= v.Index; i++)
- context.Type.GenericParameters.Add (new GenericParameter (i, context.Type));
- }
-
protected object GetConstant (uint pos, ElementType elemType)
{
byte [] constant = m_root.Streams.BlobHeap.Read (pos);