• c# 反射备忘


    1.调用静态类public静态普通方法 ExecuteDataTable

    var business = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(dll => dll.ManifestModule.ScopeName.ToLower() == "firstelite.oms.business.dll");
    var sql = @"SELECT * FROM Table WHERE username=@LoginID)";
    var dt = business.GetType("Firstelite.OMS.Business.Data.OMSSqlClientManager").InvokeMember("ExecuteDataTable"
        , System.Reflection.BindingFlags.InvokeMethod
        | System.Reflection.BindingFlags.Static
        | System.Reflection.BindingFlags.Public
        , null, null, new object[] { sql, new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("@LoginID", loginID) } }) as System.Data.DataTable;

    2.调用静态类泛型类型为string的public静态方法 Convert

    var pass = business.GetType("FirsteLite.OMS.Business.Helper.ConvertHelper").GetMethod("Convert"
                        , System.Reflection.BindingFlags.InvokeMethod
                        | System.Reflection.BindingFlags.Static
                        | System.Reflection.BindingFlags.Public).MakeGenericMethod(typeof(string)).Invoke(null, new object[] { dt.Rows[0]["password"], string.Empty });
    桂棹兮兰桨,击空明兮溯流光。
  • 相关阅读:
    Fabric quickly
    jumpserver install
    Docker installs
    快速安装测试版Mysql
    centos7 usually use
    Mysql 通过frm&ibd 恢复数据
    GIT 常用方法
    诸葛亮-诫外甥书
    闭包函数(绑定函数)
    形参和实参
  • 原文地址:https://www.cnblogs.com/nanfei/p/15234950.html
Copyright © 2020-2023  润新知