Skip to content

Instantly share code, notes, and snippets.

@antiufo antiufo/gist:9917736

Last active Aug 29, 2015
Embed
What would you like to do?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
IType<Student> stud = TypeEx.GetType<Student>();
IType<object> obj = TypeEx.GetType<object>();
IType<Person> pers = stud;
stud = (IType<Student>)pers;
//IType<Person> pers = obj;
}
}
class Person
{
}
class Student : Person
{
}
public interface IType<out T>
{
Type Type { get; }
}
public static class TypeEx
{
public static IType<T> GetType<T>()
{
return new Type<T>(typeof(T));
}
}
internal class Type<T> : IType<T>
{
private Type t;
internal Type(Type t)
{
this.t = t;
}
Type IType<T>.Type
{
get
{
return t;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.