Export to GitHub

linfu - issue #22

Fixes for generic parameters in r411 are insufficient


Posted on Jul 21, 2009 by Helpful Rhino

What steps will reproduce the problem? 1. Create a non-generic type 2. Add a generic method 3. Add an out or ref parameter of the generic argument type

What is the expected output? What do you see instead? Expect to get a proxy, instead get an InvalidOperationException("Invalid context") MethodDefinitionExtensions.AddParameters, line 102.

An out parameter of generic type shows up with the following notable characteristics: type.ContainsGenericParameters == true type.IsGenericParameter == false type.IsGenericType == false type.IsGenericTypeDefinition == false type.HasElementType == true type.IsByRef == true type.GetElementType() == typeof(T) (assuming T is the generic parameter type)

My suggestion:

Change line 99 from:

if ((type.ContainsGenericParameters && type.IsGenericType) || type.IsGenericParameter)

to:

if ((type.ContainsGenericParameters && type.IsGenericType) || type.IsGenericParameter || (type.HasElementType && type.GetElementType().IsGenericParameter))

That works for me, and I think should also deal with arrays of the generic type and possibly other situations.

Comment #1

Posted on Jul 21, 2009 by Massive Bird

Fixed in revision 417.

Status: Fixed

Labels:
Type-Defect Priority-Medium