using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
namespace com
{
class Program
{
static void Main(string[] args)
{
Female famale = new Female();
Utils<Female> utils = new Utils<Female>(famale);
utils.Doing();
Male male = new Male();
Utils<Male> utils2 = new Utils<Male>(male);
utils2.Doing();
}
}
public class Male
{
public void Man(string name, string age)
{
Console.WriteLine("My name is " + name + ",I am " + age + " years old this year,I am a boy");
}
}
public class Female
{
public void Women(string name, string age)
{
Console.WriteLine("My name is " + name + ", I am " + age + " years old this year,I am a girl");
}
}
public class Utils<T>
{
T t;
public Utils(T t)
{
this.t = t;
}
public void Doing()
{
Type type = typeof(T);
if (type.ToString() == "com.Female")
{
MethodInfo info = type.GetMethod("Women");
info.Invoke(t, new object[] { "Zhang jun ying", "18" });
}
if(type.ToString()=="com.Male")
{
MethodInfo info = type.GetMethod("Man");
info.Invoke(t, new object[] { "Zhang jun ying", "18" });
}
}
}
}