J
Jarod
Hey
I have function like this:
GivenType GetData<GivenType>(...)
{
// I need to check if GivenType is System.String
the only way I found to work was:
if(typeof(GivenType) == Type.GetType("System.String")
// but here I want to do sth like this :
return (GivenType) String.Empty;
}
When I try to cast on GivenType which is in this case for 100% string I got
error in compile time, that casting is impossible. But if put String.Empty
into object type and then cast it will work fine. But it seems like not so
efficient so maybe there is a better way ? How to check for type on
GivenType any other ways than typeof ?
Jarod
I have function like this:
GivenType GetData<GivenType>(...)
{
// I need to check if GivenType is System.String
the only way I found to work was:
if(typeof(GivenType) == Type.GetType("System.String")
// but here I want to do sth like this :
return (GivenType) String.Empty;
}
When I try to cast on GivenType which is in this case for 100% string I got
error in compile time, that casting is impossible. But if put String.Empty
into object type and then cast it will work fine. But it seems like not so
efficient so maybe there is a better way ? How to check for type on
GivenType any other ways than typeof ?
Jarod