O
oscar.acostamontesde
Hello:
I'm tryn to detect if a type is a nullable type. I'm using the
following code:
using System;
using System.Reflection;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
Nullable<int> n = 0;
Console.WriteLine(IsNullableType(n.GetType()));
Console.ReadLine();
}
static bool IsNullableType(Type theType){
return (theType.GetType().IsGenericType &&
theType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)));
}
}
First call in IsNullableType returns false, where i think should return
true. And if i remove this first test (theType.GetType().IsGenericType)
it launch a System.InvalidOperationException. Anyone knows why is it
hapening, and/or how to detect if a type is a nullable type? Thanks!!
Oscar Acosta
This code launch an exception, and
I'm tryn to detect if a type is a nullable type. I'm using the
following code:
using System;
using System.Reflection;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
Nullable<int> n = 0;
Console.WriteLine(IsNullableType(n.GetType()));
Console.ReadLine();
}
static bool IsNullableType(Type theType){
return (theType.GetType().IsGenericType &&
theType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)));
}
}
First call in IsNullableType returns false, where i think should return
true. And if i remove this first test (theType.GetType().IsGenericType)
it launch a System.InvalidOperationException. Anyone knows why is it
hapening, and/or how to detect if a type is a nullable type? Thanks!!
Oscar Acosta
This code launch an exception, and