0

How to check if the object is byte[] using a reflection? I use this line of code to check typeof(T).GetType().Equals(typeof(byte[])) but it didn't work it out for me. Is this achievable?

public static SetSqlDbType<T>()
{
    switch(Type.GetTypeCode(typeof(T)))
    {
        case TypeCode.Int64:
            return SqlDbType.BigInt;
        // ... some more cases
        case TypeCode.Object:
        {
            if (typeof(T).GetType().Equals(typeof(byte)))
            {
                return SqlDbType.VarBinary;
            }
        }
    }
}
Alvin Quezon
  • 1,089
  • 3
  • 11
  • 29

2 Answers2

3

The code:

typeof(T).GetType()

returns you type of Type :)

You can check this much more simplier

typeof(T) == typeof(byte[])
Dmitriy Korolev
  • 288
  • 1
  • 10
1

You don't need the GetType():

public static bool f<T>(T x) => typeof(T).Equals(typeof(byte[]));
tymtam
  • 31,798
  • 8
  • 86
  • 126