7 using System.Xml.Serialization;
14 private void UpdateAvailableTypes()
16 DataTable DT =
new DataTable();
17 DT.Columns.Add(
"Effect type", typeof(
string));
18 DT.Columns.Add(
"Source", typeof(
string));
19 Assembly A=
System.Reflection.Assembly.GetExecutingAssembly();
20 foreach (Type T
in AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(
IEffect).IsAssignableFrom(p) && !p.IsAbstract))
22 DT.Rows.Add(T.Name,(A==T.Assembly?
"Built in":
"Scripted"));
25 AvailableEffects.ClearSelection();
26 AvailableEffects.Columns.Clear();
27 AvailableEffects.AutoGenerateColumns =
true;
28 AvailableEffects.DataSource = DT;
29 AvailableEffects.Refresh();
30 AvailableEffects.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
36 private void UpdateTypeXml()
39 if (AvailableEffects.SelectedRows.Count > 0)
41 string N = AvailableEffects.SelectedRows[0].Cells[0].Value.ToString();
42 General.TypeList Types =
new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(
IEffect).IsAssignableFrom(p) && !p.IsAbstract));
43 if (Types.Contains(N))
48 object O = Activator.CreateInstance(T);
51 foreach (PropertyInfo PI
in T.GetProperties(BindingFlags.Instance | BindingFlags.Public))
55 if (PI.PropertyType == typeof(
string) && PI.Name ==
"Name")
57 PI.SetValue(O,
"Effect name", null);
59 else if (PI.PropertyType.IsNumber())
63 else if (PI.PropertyType == typeof(
bool))
65 PI.SetValue(O,
false, null);
67 else if (PI.PropertyType == typeof(
string) && PI.Name.ToLower().Contains(
"output"))
69 PI.SetValue(O,
"Name of a output", null);
71 else if (PI.PropertyType == typeof(
string) && PI.Name.ToLower().Contains(
"toy"))
73 PI.SetValue(O,
"Name of a toy", null);
75 else if (PI.PropertyType == typeof(
string))
77 string V = (string)PI.GetValue(O, null);
78 if (V.IsNullOrWhiteSpace())
80 PI.SetValue(O,
"{0} value".Build(PI.Name), null);
83 else if (PI.PropertyType == typeof(DateTime))
85 PI.SetValue(O, DateTime.MaxValue, null);
92 XmlSerializerNamespaces EmptyNamepsaces =
new XmlSerializerNamespaces(
new[] {
System.Xml.XmlQualifiedName.Empty });
93 var Serializer =
new XmlSerializer(T);
94 var Settings =
new System.Xml.XmlWriterSettings();
95 Settings.Indent =
true;
96 Settings.OmitXmlDeclaration =
true;
99 using (var Stream =
new StringWriter())
100 using (var Writer =
System.Xml.XmlWriter.Create(Stream, Settings))
102 Serializer.Serialize(Writer, O, EmptyNamepsaces);
103 S = Stream.ToString();
109 S =
"XML Serialization failed.\nException:\n{0}".Build(E.Message);
115 S =
"Effect not found";
123 InitializeComponent();
124 UpdateAvailableTypes();
129 private void CopyToClipboard_Click(
object sender, EventArgs e)
131 if (!TypeXml.Text.IsNullOrWhiteSpace())
133 Clipboard.SetText(TypeXml.Text);
137 private void AvailableEffects_SelectionChanged(
object sender, EventArgs e)
Common interface for all effects. If a new effect is implemented it is best to inherit from the abst...
The namespace FX contains effect related classes. Effects can be assigned directly to a Table and wi...