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();
            //}

        }
    }

  • 相关阅读:
    注释驱动的 Spring cache 缓存介绍--转载
    AOP 的利器:ASM 3.0 介绍
    字符串比较报错
    Performing a thread dump in Linux or Windows--reference
    Linux 精准获取进程pid--转
    /bin/bash^M: bad interpreter: 没有那个文件或目录--转载
    linux 进程综合指令
    Sending e-mail with Spring MVC---reference
    Spring XD 1.1 M2 and 1.0.3 released---support kafka
    大数据框架对比:Hadoop、Storm、Samza、Spark和Flink——flink支持SQL,待看
  • 原文地址:https://www.cnblogs.com/bestsaler/p/1835616.html
Copyright © 2011-2022 走看看