protected static GenericParameter GetGenericParameter(GenericParameter gp, ImportContext context) { // walk generic context stack, looking for the generic parameter GenericParameter p = null; context.SearchGenericContextStack(delegate(GenericContext genericContext) { if (gp.Owner is TypeReference && genericContext.Type.GenericParameters.Count > gp.Position) { p = genericContext.Type.GenericParameters[gp.Position]; return true; } else if (gp.Owner is MethodReference && genericContext.Method.GenericParameters.Count > gp.Position) { p = genericContext.Method.GenericParameters[gp.Position]; return true; } else { return false; } }); if (p == null) { throw new NotSupportedException("Unable to find generic parameter " + gp + " in context " + context); } return p; }