您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
71 行
1.9 KiB
71 行
1.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Unity.UIWidgets.foundation {
|
|
public abstract class Key {
|
|
protected Key() {
|
|
}
|
|
|
|
public static Key key(string value) {
|
|
return new ValueKey<string>(value);
|
|
}
|
|
}
|
|
|
|
public abstract class LocalKey : Key {
|
|
protected LocalKey() {
|
|
}
|
|
}
|
|
|
|
public class ValueKey<T> : LocalKey, IEquatable<ValueKey<T>> {
|
|
public ValueKey(T value) {
|
|
this.value = value;
|
|
}
|
|
|
|
public readonly T value;
|
|
|
|
public bool Equals(ValueKey<T> other) {
|
|
if (ReferenceEquals(null, other)) {
|
|
return false;
|
|
}
|
|
if (ReferenceEquals(this, other)) {
|
|
return true;
|
|
}
|
|
return EqualityComparer<T>.Default.Equals(this.value, other.value);
|
|
}
|
|
|
|
public override bool Equals(object obj) {
|
|
if (ReferenceEquals(null, obj)) {
|
|
return false;
|
|
}
|
|
if (ReferenceEquals(this, obj)) {
|
|
return true;
|
|
}
|
|
if (obj.GetType() != this.GetType()) {
|
|
return false;
|
|
}
|
|
return this.Equals((ValueKey<T>) obj);
|
|
}
|
|
|
|
public override int GetHashCode() {
|
|
return EqualityComparer<T>.Default.GetHashCode(this.value);
|
|
}
|
|
|
|
public static bool operator ==(ValueKey<T> left, ValueKey<T> right) {
|
|
return Equals(left, right);
|
|
}
|
|
|
|
public static bool operator !=(ValueKey<T> left, ValueKey<T> right) {
|
|
return !Equals(left, right);
|
|
}
|
|
|
|
public override string ToString() {
|
|
string valueString = typeof(T) == typeof(string) ? "<\'" + this.value + "\'>" : "<" + this.value + ">";
|
|
|
|
if (this.GetType() == typeof(ValueKey<T>)) {
|
|
return $"[{valueString}]";
|
|
}
|
|
|
|
return $"[{this.GetType()} {valueString}]";
|
|
}
|
|
}
|
|
}
|