zoukankan      html  css  js  c++  java
  • C# 动态调用泛型方法

    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;
                }
            }
    --------------------- 
    作者:正怒月神 
    来源:CSDN 
    原文:https://blog.csdn.net/hanjun0612/article/details/84954340 
    版权声明:本文为博主原创文章,转载请附上博文链接!
  • 相关阅读:
    spark shuffle 机制
    hive explain 源码分析
    前端jQurey
    js-dom操作
    前端JS
    前端CSS
    Redis和MongoDB区别
    MySQL数据库备份
    MySQL索引
    python连接mysql服务端
  • 原文地址:https://www.cnblogs.com/hanjun0612/p/10101938.html
Copyright © 2011-2022 走看看