zoukankan      html  css  js  c++  java
  • 简单的反射例子及调用方法

    简单的反射例子及调用方法

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Reflection;
    using System.Data.SqlClient;

    namespace domain.UI.News.Controls
    {
        public partial class Index : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
               
                // Assembly a = Assembly.LoadFrom(@"D:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\反射\ClassLibrary1\bin\Debug\ClassLibrary1.dll");//类库的存储路径
                Assembly a = Assembly.LoadFrom(HttpRuntime.BinDirectory + @"domain.UI.dll");//类库的存储路径
                Type type = a.GetType("domain.UI.News.Controls.TestAssembly");//此处必须为类的完整名称
              
                Object o = Activator.CreateInstance(type);//实例化类
                foreach (MemberInfo mi in type.GetMethods())
                {
                    Response.Write(mi.Name+"<br>");
                }
                MethodInfo method_add = type.GetMethod("add");//得到方法的信息
                string i = (string)method_add.Invoke(o, new object[] { 1, new int[] { 2, 6 }, new SqlParameter("@C_ID", "wangdetian"), new string[] { "12","11"} });//实现方法
                Response.Write(i);
            }
        }
        public class TestAssembly
        {
            public string add(int i,int[] j,SqlParameter pas,params string[] aaa)
            {
                return (i + j[1]).ToString()+pas.Value.ToString()+aaa.Length;
               
            }
            //public string add(int i, int j,int z)
            //{
            //    return (i + j+z).ToString();
            //}

        }
    }

  • 相关阅读:
    jQuery index()方法使用
    杂记
    Tp框架代码杂记
    tp U方法的{:U('Index/index',array('id'=>$vo[id]))}
    mb_substr=0,5,'utf-8'
    Thinkphp 超长sql语句编写
    http_build_query()生成url字符串
    html_entity_decode 将数据库里的 | 互联网金融 &ldquo;野蛮生长&rdquo; 的休止符| &rdquo转义成”“
    ThinkPHP 左右定界符
    python中unicode和str的组合
  • 原文地址:https://www.cnblogs.com/bestsaler/p/1835616.html
Copyright © 2011-2022 走看看