-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathScriptContent.cs
42 lines (34 loc) · 1.09 KB
/
ScriptContent.cs
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
using System;
using System.IO;
using System.Windows.Forms;
using System.Xml.Linq;
using ReClassNET.Util;
namespace PythonScriptingPlugin
{
public class ScriptContent
{
public string Name { get; set; }
public string Content { get; set; }
public Keys HotKey { get; set; }
public void WriteTo(TextWriter writer)
{
var document = new XDocument(
new XElement("script",
XElementSerializer.ToXml(nameof(Name), Name),
XElementSerializer.ToXml(nameof(Content), Content),
XElementSerializer.ToXml(nameof(HotKey), (int)HotKey)
)
);
document.Save(writer);
}
public static ScriptContent ReadFrom(TextReader reader)
{
var document = XDocument.Load(reader);
var script = new ScriptContent();
XElementSerializer.TryRead(document.Root, nameof(Name), e => script.Name = XElementSerializer.ToString(e));
XElementSerializer.TryRead(document.Root, nameof(Content), e => script.Content = XElementSerializer.ToString(e));
XElementSerializer.TryRead(document.Root, nameof(HotKey), e => script.HotKey = (Keys)XElementSerializer.ToInt(e));
return script;
}
}
}