From 773ea99cb3329972a49e3c72a666e4684bb2bc56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=BB=BA=E5=8D=8E?= Date: Thu, 22 Nov 2018 21:46:24 +0800 Subject: [PATCH] Change some internal designs. --- YandereSpider/BindingBase/Bindable.cs | 65 +++------------------------ YandereSpider/ConsoleWindow.cs | 13 ++++-- YandereSpider/Helpers/ParamReader.cs | 2 +- 3 files changed, 16 insertions(+), 64 deletions(-) diff --git a/YandereSpider/BindingBase/Bindable.cs b/YandereSpider/BindingBase/Bindable.cs index 5d6759c..f41a3d8 100644 --- a/YandereSpider/BindingBase/Bindable.cs +++ b/YandereSpider/BindingBase/Bindable.cs @@ -16,7 +16,7 @@ namespace XstarS.ComponentModel /// 并会替换 事件委托,破坏绑定关系。 /// /// 中用于数据绑定的值的类型。 - public class Bindable : BindableObject, IEquatable> + public class Bindable : BindableObject { /// /// 当前 实例用于数据绑定的值。 @@ -26,13 +26,13 @@ public class Bindable : BindableObject, IEquatable> /// /// 使用默认值初始化 类的新实例。 /// - public Bindable() => this.value = default(T); + public Bindable() => this.Value = default(T); /// /// 使用指定的值初始化 类的新实例。 /// /// 一个 类型的对象。 - public Bindable(T value) => this.value = value; + public Bindable(T value) => this.Value = value; /// /// 当前 实例用于数据绑定的值。 @@ -47,66 +47,11 @@ public T Value set => this.SetProperty(ref this.value, value); } - /// - /// 返回一个值,该值指示此实例和指定的对象是否表示相同的值。 - /// - /// 要与此实例比较的对象。 - /// - /// 如果 的实例, - /// 且 属性相等, - /// 则为 ;否则为 。 - /// - public override bool Equals(object obj) => this.Equals(obj as Bindable); - - /// - /// 返回此实例的哈希代码。 - /// - /// 32 位有符号整数哈希代码。 - public override int GetHashCode() => - -1584136870 + EqualityComparer.Default.GetHashCode(this.value); - /// /// 返回表示当前实例的值的字符串。 /// /// 的等效字符串表达形式。 - public override string ToString() => this.value.ToString(); - - /// - /// 返回一个值,该值指示此实例和指定的 对象是否表示相同的值。 - /// - /// 要与此实例比较的 对象。 - /// - /// 如果此实例和 属性相等, - /// 则为 ;否则为 。 - /// - public bool Equals(Bindable other) => - !(other is null) && EqualityComparer.Default.Equals(this.value, other.value); - - /// - /// 指示两 对象是否相等。 - /// - /// 第一个对象。 - /// 第二个对象。 - /// - /// 如果 - /// 等于 , - /// 则为 ;否则为 。 - /// - public static bool operator ==(Bindable bindable1, Bindable bindable2) => - EqualityComparer>.Default.Equals(bindable1, bindable2); - - /// - /// 指示两 对象是否不等。 - /// - /// 第一个对象。 - /// 第二个对象。 - /// - /// 如果 - /// 不等于 , - /// 则为 ;否则为 。 - /// - public static bool operator !=(Bindable bindable1, Bindable bindable2) => - !(bindable1 == bindable2); + public override string ToString() => this.Value.ToString(); /// /// 创建一个新的 对象,并将其用于数据绑定的值初始化为指定的值。 @@ -120,6 +65,6 @@ public T Value /// /// 一个 对象。 /// 用于数据绑定的值。 - public static implicit operator T(Bindable bindable) => bindable.value; + public static implicit operator T(Bindable bindable) => bindable.Value; } } diff --git a/YandereSpider/ConsoleWindow.cs b/YandereSpider/ConsoleWindow.cs index fb6c12f..52ba5d6 100644 --- a/YandereSpider/ConsoleWindow.cs +++ b/YandereSpider/ConsoleWindow.cs @@ -20,6 +20,10 @@ public static class ConsoleWindow /// private static readonly object SyncRoot = new object(); /// + /// 指示控制台模式的主要过程是否已经启动。 + /// + private static bool IsStarted = false; + /// /// 当前正在工作的后台线程的数量。 /// private static int WorkingThreads = -1; @@ -38,8 +42,8 @@ public static class ConsoleWindow /// 程序的启动参数。 public static void Show(string[] args) { - ConsoleManager.Show(); - ConsoleWindow.Run(args); + if (!ConsoleManager.HasConsole) { ConsoleManager.Show(); } + if (!ConsoleWindow.IsStarted) { ConsoleWindow.Run(args); } } /// @@ -47,7 +51,7 @@ public static void Show(string[] args) /// public static void Hide() { - ConsoleManager.Hide(); + if (ConsoleManager.HasConsole) { ConsoleManager.Hide(); } } /// @@ -56,6 +60,9 @@ public static void Hide() /// 程序的启动参数。 private static void Run(string[] args) { + if (ConsoleWindow.IsStarted) { return; } + else { ConsoleWindow.IsStarted = true; } + var param = new ParamReader(args, true, new[] { "-e", "-t", "-o" }, new[] { "-h" }); if (param.GetSwitch("-h")) { diff --git a/YandereSpider/Helpers/ParamReader.cs b/YandereSpider/Helpers/ParamReader.cs index 3ed05bf..a054798 100644 --- a/YandereSpider/Helpers/ParamReader.cs +++ b/YandereSpider/Helpers/ParamReader.cs @@ -37,7 +37,7 @@ internal class ParamReader /// 初始化命令行参数解析器 的新实例。 /// /// - /// 输入的参数名称列表用于解析无名参数;若无需解析无名参数,可不写。 + /// 输入的参数名称列表用于解析无名参数;若无需解析无名参数,可留空。 /// /// 待解析的参数列表。 /// 参数名称是否忽略大小写。