01.// Test.dll библиотекасдан assembly'ни динамик тарзда юклаймиз:
02.Assembly testAssembly = Assembly.LoadFile(@"c:\Test.dll");
03.
04.// хозиргина юкланган assembly дан Calculator классини турини аниқлаб оламиз:
05.Type calcType = testAssembly.GetType("Test.Calculator");
06.
07.// Calculator классига мансуб бўлган объектни тузамиз:
08.object calcInstance = Activator.CreateInstance(calcType);
09.
10.// Number хоссаси хақида маълумот оламиз:
11.PropertyInfo numberPropertyInfo = calcType.GetProperty("Number");
12.
13.// Number хоссассини қийматини оламиз.
14.double value = (double)numberPropertyInfo.GetValue(calcInstance, null);
15.
16.// Number хоссасига қиймат белгилаймиз:
17.numberPropertyInfo.SetValue(calcInstance, 10.0, null);
18.
19.// Статик Pi хоссаси хақида маълумот оламиз:
20.PropertyInfo piPropertyInfo = calcType.GetProperty("Pi");
21.
22.// Статик Pi хоссасини қийматини оламиз:
23.double piValue = (double)piPropertyInfo.GetValue(null, null);
24.
25.// public кўриниш доирасидаги Clear() методини чақирамиз:
26.calcType.InvokeMember("Clear",
27.BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, calcInstance, null);
28.
29.// private кўриниш доирасидаги DoClear() методини чақирамиз:
30.calcType.InvokeMember("DoClear",
31.BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic, null, calcInstance, null);
32.
33.
34.// Add(double number) методини чақирамиз:
35.double value = (double)calcType.InvokeMember("Add",
36.BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, calcInstance, new object[] { 20.0 });
37.
38.// GetPi() статик методини чақирамиз:
39.double piValue = (double)calcType.InvokeMember("GetPi",
40.BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null, null);
41.
42.// private кўриниш доирасидаги _number ўзгарувчисини қийматини оламиз:
43.double value = (double)calcType.InvokeMember("_number",
44.BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic, null, calcInstance, null);