Example:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;//used for late binding
using India;//used for early binding
namespace TestEarlyAndLateBinding
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//early binding
private void button2_Click_1(object sender, EventArgs e)
{
Employee emp = new Employee();
MessageBox.Show(emp.EmployeeName());
}
//late binding
private void button1_Click_1(object sender, EventArgs e)
{
Assembly ptr = Assembly.LoadFrom(@"D:\TestBinding\LateBinding\Employee.dll");
Type type = ptr.GetType("India.Employee");//import name space and its class
object obj = Activator.CreateInstance(type);
MethodInfo mInfo = type.GetMethod("EmployeeName");
MessageBox.Show(mInfo.Invoke(obj, null).ToString());
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;//used for late binding
using India;//used for early binding
namespace TestEarlyAndLateBinding
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//early binding
private void button2_Click_1(object sender, EventArgs e)
{
Employee emp = new Employee();
MessageBox.Show(emp.EmployeeName());
}
//late binding
private void button1_Click_1(object sender, EventArgs e)
{
Assembly ptr = Assembly.LoadFrom(@"D:\TestBinding\LateBinding\Employee.dll");
Type type = ptr.GetType("India.Employee");//import name space and its class
object obj = Activator.CreateInstance(type);
MethodInfo mInfo = type.GetMethod("EmployeeName");
MessageBox.Show(mInfo.Invoke(obj, null).ToString());
}
}
}
No comments:
Post a Comment