Converting Generic Type into reference type after checking its type using GetType(). How ?
- by Shantanu Gupta
i am trying to call a function that is defined in a class RFIDeas_Wrapper(dll being used).
But when i checked for type of reader and after that i used it to call function it shows me error Cannot convert type T to RFIDeas_Wrapper.
EDIT
private List<string> GetTagCollection<T>(T Reader)
{
TagCollection = new List<string>();
if (Reader.GetType() == typeof(RFIDeas_Wrapper))
{
((RFIDeas_Wrapper)Reader).OpenDevice();
// here Reader is of type RFIDeas_Wrapper
//, but i m not able to convert Reader into its datatype.
string Tag_Id = ((RFIDeas_Wrapper)Reader).TagID();
//Adds Valid Tag Ids into the collection
if(Tag_Id!="0")
TagCollection.Add(Tag_Id);
}
else if (Reader.GetType() == typeof(AlienReader))
TagCollection = ((AlienReader)Reader).TagCollection;
return TagCollection;
}
((RFIDeas_Wrapper)Reader).OpenDevice(); , ((AlienReader)Reader).TagCollection;
I want this line to be executed without any issue. As Reader will always be of the type i m specifying.
How to make compiler understand the same thing.