The MakeGenericType
method converts an unbound into a closed generic type.
using System;
using System.Reflection;
using System.Collections.Generic;
class Program
{
static void Main()
{
Type unbound = typeof(List<>);
Type closed = unbound.MakeGenericType(typeof(int));
Type unbound2 = closed.GetGenericTypeDefinition(); // unbound == unbound2
}
}
IsGenericType property is true if a Type is generic
The following tests whether a type is a nullable value type:
using System;
using System.Reflection;
using System.Collections.Generic;
class Program
{
static void Main()
{
Type nullable = typeof(bool?);
Console.WriteLine(nullable.IsGenericType && nullable.GetGenericTypeDefinition() == typeof(Nullable<>));
}
}
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |