tags:

views:

26

answers:

1

I tried to retrieve the TYPE for "PreProcess" from DomainDB class using

Type.GetType("DomainDBManager.DomainDB`1[System.String]+PreProcess") 

but this is returning null. Is there anyway to get the Public Field "PreProcess" using Type.GetType?

namespace DomainDBManager { public class DomainDB<T> { public Action<string> PreProcess; } }

+2  A: 

You're currently trying to get a type by name - PreProcess is a field of the DomainDB<T> type, so Type.GetType isn't going to work. You need to get the type first, and then get the field from that:

Type type = Type.GetType("DomainDBManager.DomainDB`1[System.String]");
FieldInfo field = type.GetField("PreProcess");
Type fieldType = field.FieldType;
Jon Skeet
Yes thats right. My requirement is to get the Type for a public delegate inside the generic class.
AJP
@AJP: When you say a "public delegate" that's not very clear... if it were a delegate type declaration, your original code would be fine. However, it's a *field* whose type happens to be a delegate type. The fact that it's a delegate type is actually irrelevant.
Jon Skeet
@JonSkeet: I actually meant Field, sorry for the confusion. The solution which you provided worked perfectly fine. Thanks
AJP