Skip to content

Commit

Permalink
Change some internal designs.
Browse files Browse the repository at this point in the history
  • Loading branch information
x-stars committed Nov 22, 2018
1 parent 06b98ef commit 773ea99
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 64 deletions.
65 changes: 5 additions & 60 deletions YandereSpider/BindingBase/Bindable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace XstarS.ComponentModel
/// 并会替换 <see cref="INotifyPropertyChanged.PropertyChanged"/> 事件委托,破坏绑定关系。
/// </para></remarks>
/// <typeparam name="T"><see cref="Bindable{T}"/> 中用于数据绑定的值的类型。</typeparam>
public class Bindable<T> : BindableObject, IEquatable<Bindable<T>>
public class Bindable<T> : BindableObject
{
/// <summary>
/// 当前 <see cref="Bindable{T}"/> 实例用于数据绑定的值。
Expand All @@ -26,13 +26,13 @@ public class Bindable<T> : BindableObject, IEquatable<Bindable<T>>
/// <summary>
/// 使用默认值初始化 <see cref="Bindable{T}"/> 类的新实例。
/// </summary>
public Bindable() => this.value = default(T);
public Bindable() => this.Value = default(T);

/// <summary>
/// 使用指定的值初始化 <see cref="Bindable{T}"/> 类的新实例。
/// </summary>
/// <param name="value">一个 <typeparamref name="T"/> 类型的对象。</param>
public Bindable(T value) => this.value = value;
public Bindable(T value) => this.Value = value;

/// <summary>
/// 当前 <see cref="Bindable{T}"/> 实例用于数据绑定的值。
Expand All @@ -47,66 +47,11 @@ public T Value
set => this.SetProperty(ref this.value, value);
}

/// <summary>
/// 返回一个值,该值指示此实例和指定的对象是否表示相同的值。
/// </summary>
/// <param name="obj">要与此实例比较的对象。</param>
/// <returns>
/// 如果 <paramref name="obj"/> 是 <see cref="Bindable{T}"/> 的实例,
/// 且 <see cref="Bindable{T}.Value"/> 属性相等,
/// 则为 <see langword="true"/>;否则为 <see langword="false"/>。
/// </returns>
public override bool Equals(object obj) => this.Equals(obj as Bindable<T>);

/// <summary>
/// 返回此实例的哈希代码。
/// </summary>
/// <returns>32 位有符号整数哈希代码。</returns>
public override int GetHashCode() =>
-1584136870 + EqualityComparer<T>.Default.GetHashCode(this.value);

/// <summary>
/// 返回表示当前实例的值的字符串。
/// </summary>
/// <returns><see cref="Bindable{T}.Value"/> 的等效字符串表达形式。</returns>
public override string ToString() => this.value.ToString();

/// <summary>
/// 返回一个值,该值指示此实例和指定的 <see cref="Bindable{T}"/> 对象是否表示相同的值。
/// </summary>
/// <param name="other">要与此实例比较的 <see cref="Bindable{T}"/> 对象。</param>
/// <returns>
/// 如果此实例和 <paramref name="other"/> 的 <see cref="Bindable{T}.Value"/> 属性相等,
/// 则为 <see langword="true"/>;否则为 <see langword="false"/>。
/// </returns>
public bool Equals(Bindable<T> other) =>
!(other is null) && EqualityComparer<T>.Default.Equals(this.value, other.value);

/// <summary>
/// 指示两 <see cref="Bindable{T}"/> 对象是否相等。
/// </summary>
/// <param name="bindable1">第一个对象。</param>
/// <param name="bindable2">第二个对象。</param>
/// <returns>
/// 如果 <paramref name="bindable1"/> 的 <see cref="Bindable{T}.Value"/>
/// 等于 <paramref name="bindable2"/> 的 <see cref="Bindable{T}.Value"/>,
/// 则为 <see langword="true"/>;否则为 <see langword="false"/>。
/// </returns>
public static bool operator ==(Bindable<T> bindable1, Bindable<T> bindable2) =>
EqualityComparer<Bindable<T>>.Default.Equals(bindable1, bindable2);

/// <summary>
/// 指示两 <see cref="Bindable{T}"/> 对象是否不等。
/// </summary>
/// <param name="bindable1">第一个对象。</param>
/// <param name="bindable2">第二个对象。</param>
/// <returns>
/// 如果 <paramref name="bindable1"/> 的 <see cref="Bindable{T}.Value"/>
/// 不等于 <paramref name="bindable2"/> 的 <see cref="Bindable{T}.Value"/>,
/// 则为 <see langword="true"/>;否则为 <see langword="false"/>。
/// </returns>
public static bool operator !=(Bindable<T> bindable1, Bindable<T> bindable2) =>
!(bindable1 == bindable2);
public override string ToString() => this.Value.ToString();

/// <summary>
/// 创建一个新的 <see cref="Bindable{T}"/> 对象,并将其用于数据绑定的值初始化为指定的值。
Expand All @@ -120,6 +65,6 @@ public T Value
/// </summary>
/// <param name="bindable">一个 <see cref="Bindable{T}"/> 对象。</param>
/// <returns><paramref name="bindable"/> 用于数据绑定的值。</returns>
public static implicit operator T(Bindable<T> bindable) => bindable.value;
public static implicit operator T(Bindable<T> bindable) => bindable.Value;
}
}
13 changes: 10 additions & 3 deletions YandereSpider/ConsoleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public static class ConsoleWindow
/// </summary>
private static readonly object SyncRoot = new object();
/// <summary>
/// 指示控制台模式的主要过程是否已经启动。
/// </summary>
private static bool IsStarted = false;
/// <summary>
/// 当前正在工作的后台线程的数量。
/// </summary>
private static int WorkingThreads = -1;
Expand All @@ -38,16 +42,16 @@ public static class ConsoleWindow
/// <param name="args">程序的启动参数。</param>
public static void Show(string[] args)
{
ConsoleManager.Show();
ConsoleWindow.Run(args);
if (!ConsoleManager.HasConsole) { ConsoleManager.Show(); }
if (!ConsoleWindow.IsStarted) { ConsoleWindow.Run(args); }
}

/// <summary>
/// 隐藏命令行窗口,释放标准输入流和错误流。
/// </summary>
public static void Hide()
{
ConsoleManager.Hide();
if (ConsoleManager.HasConsole) { ConsoleManager.Hide(); }
}

/// <summary>
Expand All @@ -56,6 +60,9 @@ public static void Hide()
/// <param name="args">程序的启动参数。</param>
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"))
{
Expand Down
2 changes: 1 addition & 1 deletion YandereSpider/Helpers/ParamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal class ParamReader
/// 初始化命令行参数解析器 <see cref="ParamReader"/> 的新实例。
/// </summary>
/// <remarks>
/// 输入的参数名称列表用于解析无名参数;若无需解析无名参数,可不写
/// 输入的参数名称列表用于解析无名参数;若无需解析无名参数,可留空
/// </remarks>
/// <param name="arguments">待解析的参数列表。</param>
/// <param name="ignoreCase">参数名称是否忽略大小写。</param>
Expand Down

0 comments on commit 773ea99

Please sign in to comment.