static void Main(string[] args)
{
#region 具体类型可传递。
Personal specifiedPersonal = new Personal();
Employee<Personal> employee = new Employee<Personal>();
employee.Create(specifiedPersonal);
#endregion
#region 动态类型传递到TModel。
//假设传递一个a进来
Personal a = new Personal();
var type = typeof(Employee<>).MakeGenericType(a.GetType());
dynamic a_Context = Activator.CreateInstance(type);
var q = a_Context.Create(a);
Console.WriteLine(q);
#endregion
Console.ReadLine();
}
public class Personal
{
public string FirstName { get; internal set; }
public string LastName { get; internal set; }
}
public interface IEmployee<TModel>
{
Guid Create(TModel model);
bool Update(TModel model);
}
public class Employee<TModel> : IEmployee<TModel>
{
public Guid Create(TModel model)
{
// TODO :
return Guid.NewGuid();
}
public bool Update(TModel model)
{
// TODO :
return true;
}
}