GetConstructor on Generic Classes.

U

Undergrid

Given the following example class:

public class genericClass<T>
{
public genericClass() {}
public genericClass(IEnumerable<T> a) { /* do something with a
*/ }
public genericClass(T b) { /* do something with b */ }
}

And the following code:

Type t = typeof ( genericClass<testClass> );

Is there anyway to call t.GetConstructor to get the ConstructorInfo
about the constructor genericClass(IEnumerable<T> a) ? At the point I
want to call GetConstructore I also have a Type class describing
testClass if that helps.

Thanks

Nick
 
B

Barry Kelly

Undergrid said:
Given the following example class:

public class genericClass<T>
{
public genericClass() {}
public genericClass(IEnumerable<T> a) { /* do something with a
*/ }
public genericClass(T b) { /* do something with b */ }
}

And the following code:

Type t = typeof ( genericClass<testClass> );

Is there anyway to call t.GetConstructor to get the ConstructorInfo
about the constructor genericClass(IEnumerable<T> a) ? At the point I
want to call GetConstructore I also have a Type class describing
testClass if that helps.

You should be able to. Have you tried using
'typeof(IEnumerable<>).MakeGenericType(typeof(testClass))' as the
argument type?

-- Barry
 
U

Undergrid

You should be able to. Have you tried using
'typeof(IEnumerable<>).MakeGenericType(typeof(testClass))' as the
argument type?

-- Barry

--http://barrkel.blogspot.com/

Thank you Barry, that does the job nicely. I knew there had to be a
way to do it, I just couldn't figure out how.

Thanks

Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top