码迷,mamicode.com
首页 > 其他好文 > 详细

Assembly(程序集)

时间:2016-05-10 12:25:18      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Winfrom
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            Assembly asm = Assembly.Load("Winfrom");
            var type = asm.GetType("Winfrom.Test");

            var instance = asm.CreateInstance("Winfrom.Test");

            type.GetProperty("Name").SetValue(instance, "hello world", null);
            type.GetProperty("Id").SetValue(instance, 1, null);

            var method = type.GetMethod("Hello");
            method.Invoke(instance, null);

        }
    }

    public class Test
    {
        private int id;
        private string name;

        public int Id
        {
            get { return this.id; }
            set { this.id = value; }
        }

        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        public void Hello()
        {
            MessageBox.Show(Name);
        }
    }
}

 

Assembly(程序集)

标签:

原文地址:http://www.cnblogs.com/xiaoqi742709106/p/5477321.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!