Line | |
---|
1 | using System;
|
---|
2 | using System.Reflection;
|
---|
3 | using System.Windows.Forms;
|
---|
4 |
|
---|
5 | namespace HeuristicLab.Visualization.DataExport {
|
---|
6 | public partial class ExportDialog : Form {
|
---|
7 | public ExportDialog() {
|
---|
8 | InitializeComponent();
|
---|
9 |
|
---|
10 | Type[] types = Assembly.GetExecutingAssembly().GetTypes();
|
---|
11 | foreach (Type type in types) {
|
---|
12 | if (type.GetInterface(typeof (IExporter).FullName) != null) {
|
---|
13 | IExporter exporter = (IExporter)Activator.CreateInstance(type);
|
---|
14 |
|
---|
15 | lbExporters.Items.Add(CreateListBoxItem(exporter));
|
---|
16 | }
|
---|
17 | }
|
---|
18 | }
|
---|
19 |
|
---|
20 | private static ListBoxItem CreateListBoxItem(IExporter exporter) {
|
---|
21 | return new ListBoxItem(exporter);
|
---|
22 | }
|
---|
23 |
|
---|
24 | private void btnCancel_Click(object sender, EventArgs e) {
|
---|
25 | selectedExporter = null;
|
---|
26 | Close();
|
---|
27 | }
|
---|
28 |
|
---|
29 | private void btnSelectExporter_Click(object sender, EventArgs e) {
|
---|
30 | selectedExporter = ((ListBoxItem)lbExporters.SelectedItem).Exporter;
|
---|
31 | Close();
|
---|
32 | }
|
---|
33 |
|
---|
34 | private IExporter selectedExporter;
|
---|
35 |
|
---|
36 | public IExporter SelectedExporter {
|
---|
37 | get { return selectedExporter; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | private class ListBoxItem {
|
---|
41 | private readonly IExporter exporter;
|
---|
42 |
|
---|
43 | public ListBoxItem(IExporter exporter) {
|
---|
44 | this.exporter = exporter;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public IExporter Exporter {
|
---|
48 | get { return exporter; }
|
---|
49 | }
|
---|
50 |
|
---|
51 | public override string ToString() {
|
---|
52 | return exporter.Name;
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.