欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

反射示例1-----執(zhí)行反射dll的方法和獲取屬性的值

項目結構:

成都創(chuàng)新互聯(lián)主打移動網站、成都做網站、網站設計、網站改版、網絡推廣、網站維護、國際域名空間、等互聯(lián)網信息服務,為各行業(yè)提供服務。在技術實力的保障下,我們?yōu)榭蛻舫兄Z穩(wěn)定,放心的服務,根據(jù)網站的內容與功能再決定采用什么樣的設計。最后,要實現(xiàn)符合網站需求的內容、功能與設計,我們還會規(guī)劃穩(wěn)定安全的技術方案做保障。

反射示例1-----執(zhí)行反射dll的方法和獲取屬性的值

將Document類庫生成的DLL文件放在ConsoleApplication2\ConsoleApplication2\bin\Debug文件夾下

-------------------------------------------------------------Document.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Document
{
    public class Document
    {
        public string Name = "李四";
        public string GetName(string name)
        {
            return name;
        }
    }
}

 -------------------------------------------------------------Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.IO;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            //獲取程序集
            Assembly asb = Assembly.LoadFrom(Directory.GetCurrentDirectory() + "/Document.dll");
            //獲取程序集下面的Document類
            Type document = asb.GetType("Document.Document");
            //實例化Document類對象(有參數(shù)的話需要傳遞object參數(shù))
            object docObj = Activator.CreateInstance(document);
            //獲取Document類中的方法
            MethodInfo mi = document.GetMethod("GetName");
            //參數(shù)
            object[] parameter = new object[] { "張三" };
            Console.WriteLine(mi.Invoke(docObj, parameter).ToString());//輸出方法的返回值:張三
            //獲取Document類中的屬性
            FieldInfo pi = document.GetField("Name");
            Console.WriteLine(pi.GetValue(docObj));//輸出方法的屬性:李四
            Console.ReadKey();
        }
    }
}

文章題目:反射示例1-----執(zhí)行反射dll的方法和獲取屬性的值
瀏覽地址:http://chinadenli.net/article44/gpjjee.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供外貿網站建設企業(yè)建站、網站改版、網站設計公司、網站制作、Google

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

網站優(yōu)化排名