zoukankan      html  css  js  c++  java
  • 反射的常见应用

    /*
     *
     * 创建人:李林峰
     *
     * 时  间:2012-7-23
     *
     * 描  述:应用程序入口
     *
     */
    using System.Reflection;//反射的名称空间
    using CSharp.Model;     //实体名称空间
    namespace CSharp.Reflection
    {
        class Program
        {
            static void Main(string[] args)
            {
                Employee employee = (Employee)Assembly.Load(Constant.ASSEMBLYNAME).CreateInstance("CSharp.Model.Employee");
                employee.ID = 1;
                employee.Name = "李林峰";
                employee.Department = "技术";
                employee.Position = "程序员";
                System.Console.WriteLine(employee.Name);
                System.Console.WriteLine(employee.Department);
                System.Console.WriteLine(employee.Position);
                System.Console.WriteLine(employee.Method());
                System.Console.WriteLine("---------------------------------");
                Employee employeeNew = (Employee)Assembly.LoadFile(@"E:公司内网HZYT.Test6 C#映射教程ClassThreeCSharp.ReflectioninDebugCSharp.Model.dll").CreateInstance("CSharp.Model.Employee");
                employee.ID = 2;
                employeeNew.Name = "李林峰";
                employeeNew.Department = "技术";
                employeeNew.Position = "程序员";
                System.Console.WriteLine(employeeNew.Name);
                System.Console.WriteLine(employeeNew.Department);
                System.Console.WriteLine(employeeNew.Position);
                System.Console.WriteLine(employee.Method());
            }
        }
    }
     
    #引用的类库函数如下
    /*
     *
     * 创建人:李林峰
     *
     * 时  间:2012-7-23
     *
     * 描  述:反射类的实例
     *
     */
    using System;
    using System.Collections.Generic;
    using System.Text;
    namespace CSharp.Model
    {
        /// <summary>
        /// 员工类
        /// </summary>
        public class Employee
        {
            public int ID { get; set; }             //编号
            public string Name { get; set; }        //姓名
            public string Password { get; set; }    //密码
            public string Department { get; set; }  //部门
            public string Position { get; set; }    //职位
            /// <summary>
            /// 测试方法
            /// </summary>
            /// <returns></returns>
            public string Method()
            {
                return this.ID.ToString();
            }
        }
    }
     
    转自 :http://www.cnblogs.com/iamlilinfeng 多谢李林峰大佬
    反射的两种常见应用,记录一下
  • 相关阅读:
    Fiddler 教程
    Snippet Compiler——代码段编译工具
    HTML5 Audio时代的MIDI音乐文件播放
    sql 数据库 庞大数据量 需要分表
    使用LINQ查询非泛型类型
    找出numpy array数组的最值及其索引
    list的*运算使用过程中遇到的问题
    4.keras实现-->生成式深度学习之用GAN生成图像
    np.repeat 与 np.tile
    pandas中的axis=0,axis=1,傻傻分不清楚
  • 原文地址:https://www.cnblogs.com/yangzh666/p/11471343.html
Copyright © 2011-2022 走看看