Bonjour,
Je me retrouve avec 2 version d'un code qui font plus ou moins la même chose. Pourriez-vous me dire lequel vous semble le plus intéressant à exploiter ?
code 1 :
code 2 :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 using PluginContract; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace MyApp { public partial class Form1 : Form { object obj; AppDomain domain1 = AppDomain.CreateDomain("domain1"); public object plugin1() { obj = domain1.CreateInstanceAndUnwrap("Plugin1", "Plugin1.Plugin1"); return richTextBox1.Text += ((IPlugin)obj).Compter(); } object obj2; AppDomain domain2 = AppDomain.CreateDomain("domain2"); public object plugin2() { obj2 = domain2.CreateInstanceAndUnwrap("Plugin2", "Plugin2.Plugin2"); return ((IPlugin)obj2).Compter(); } AppDomain domain3 = AppDomain.CreateDomain("domain3"); object obj3 ; public object plugin3() { obj3 = domain3.CreateInstanceAndUnwrap("Plugin3", "Plugin3.Plugin3"); return ((IPlugin)obj3).Compter(); } public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { plugin1(); } private void button2_Click(object sender, EventArgs e) { richTextBox1.Text += plugin2(); } private void button3_Click(object sender, EventArgs e) { richTextBox1.Text += plugin3(); } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 using PluginContract; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace MyApp { public partial class Form1 : Form { ICollection<IPlugin> plugins = PluginLoader.LoadPlugins("Plugins"); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { foreach(IPlugin item in plugins){ if(item.Nom()=="Plugin1"){ richTextBox1.Text += "Plugin : " + item.Nom() + "valeur : " + item.Compter(); } } } private void button2_Click(object sender, EventArgs e) { foreach (IPlugin item in plugins) { if (item.Nom() == "Plugin2") { richTextBox1.Text += "Plugin : " + item.Nom() + "valeur : " + item.Compter(); } } } private void button3_Click(object sender, EventArgs e) { foreach (IPlugin item in plugins) { if (item.Nom() == "Plugin3") { richTextBox1.Text += "Plugin : " + item.Nom() + "valeur : " + item.Compter(); } } } } }
Merci d'avance !
Partager