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