public class Outer<T> { public class Inner<U, V> { static Inner() { System.Web.HttpContext.Current.Response.Write("<br>"); System.Web.HttpContext.Current.Response.Write("Inner:"); string t = typeof(T).Name; string u = typeof(U).Name; string v = typeof(V).Name; string str = string.Format(" Outer<{0}>.Inner<{1},{2}> ", typeof(T).Name, typeof(U).Name, typeof(V).Name); System.Web.HttpContext.Current.Response.Write(str); System.Web.HttpContext.Current.Response.Write("<br>"); } public static void DummyMethod() { } } }
测试数据:
Outer<int>.Inner<string, DateTime>.DummyMethod();
Outer<string>.Inner<int, int>.DummyMethod();
Outer<object>.Inner<string, object>.DummyMethod();
Outer<string>.Inner<string, object>.DummyMethod();
Outer<object>.Inner<object, string>.DummyMethod();
Outer<string>.Inner<int, int>.DummyMethod();
结果:
Inner: Outer.Inner
Inner: Outer.Inner
Inner: Outer.Inner
Inner: Outer.Inner
Inner: Outer.Inner
实际要求结果:
Inner: Outer<Int32>.Inner<String,DateTime>
Inner: Outer<String>.Inner<Int32,Int32>
Inner: Outer<Object>.Inner<String,Object>
Inner: Outer<String>.Inner<String,Object>
Inner: Outer<Object>.Inner<Object,String>