/*
*
* 创建人:李林峰
*
* 时 间:2012-7-23
*
* 描 述:应用程序入口
*
*/
*
* 创建人:李林峰
*
* 时 间:2012-7-23
*
* 描 述:应用程序入口
*
*/
using System.Reflection;//反射的名称空间
using CSharp.Model; //实体名称空间
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());
{
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.Test 6 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());
}
}
}
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
*
* 描 述:反射类的实例
*
*/
*
* 创建人:李林峰
*
* 时 间:2012-7-23
*
* 描 述:反射类的实例
*
*/
using System;
using System.Collections.Generic;
using System.Text;
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>
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();
}
}
}
/// 测试方法
/// </summary>
/// <returns></returns>
public string Method()
{
return this.ID.ToString();
}
}
}
转自 :http://www.cnblogs.com/iamlilinfeng 多谢李林峰大佬
反射的两种常见应用,记录一下