kg
6 年前
当前提交
e77cbe99
共有 8 个文件被更改,包括 283 次插入 和 27 次删除
-
6Assets/UIWidgets/foundation/change_notifier.cs
-
2Assets/UIWidgets/foundation/debug.cs
-
126Assets/UIWidgets/foundation/node.cs
-
67Assets/UIWidgets/foundation/node.mixin.gen.cs
-
69Assets/UIWidgets/foundation/node.mixin.njk
-
20Assets/UIWidgets/widgets/basic.cs
-
16Assets/UIWidgets/widgets/framework.cs
-
4Assets/UIWidgets/widgets/text.cs
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Reflection; |
|||
|
|||
class _DependencyList : IEquatable<_DependencyList> { |
|||
internal _DependencyList(Type type, object target) { |
|||
D.assert(type != null); |
|||
this._type = type; |
|||
|
|||
var fields = _getTypeFields(type); |
|||
|
|||
this._list = new List<object>(fields.Length); |
|||
foreach (var field in fields) { |
|||
this._list.Add(field.GetValue(target)); |
|||
} |
|||
} |
|||
|
|||
readonly List<object> _list; |
|||
|
|||
readonly Type _type; |
|||
|
|||
static readonly Dictionary<Type, FieldInfo[]> _typeFields = new Dictionary<Type, FieldInfo[]>(); |
|||
|
|||
static FieldInfo[] _getTypeFields(Type type) { |
|||
FieldInfo[] fields; |
|||
if (_typeFields.TryGetValue(type, out fields)) { |
|||
return fields; |
|||
} |
|||
|
|||
_typeFields[type] = fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance); |
|||
|
|||
|
|||
D.assert(() => { |
|||
foreach (var field in fields) { |
|||
if (!field.IsInitOnly) { |
|||
throw new UIWidgetsError( |
|||
type + " should be immutable. All public fields need to be readonly. " + |
|||
field + " is not readonly."); |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
}); |
|||
|
|||
return fields; |
|||
} |
|||
|
|||
static bool _sequenceEquals(IList list1, IList list2) { |
|||
if (list1 == null && list2 == null) { |
|||
return true; |
|||
} |
|||
|
|||
if (list1 == null || list2 == null) { |
|||
return true; |
|||
} |
|||
|
|||
if (list1.Count != list2.Count) { |
|||
return false; |
|||
} |
|||
|
|||
for (var i = 0; i < list1.Count; i++) { |
|||
var item1 = list1[i]; |
|||
var item2 = list2[i]; |
|||
|
|||
if (item1 is IList && item2 is IList) { |
|||
if (!_sequenceEquals((IList) item1, (IList) item2)) { |
|||
return false; |
|||
} |
|||
} else { |
|||
if (!object.Equals(item1, item2)) { |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
public bool Equals(_DependencyList other) { |
|||
if (object.ReferenceEquals(null, other)) return false; |
|||
if (object.ReferenceEquals(this, other)) return true; |
|||
return this._type == other._type && _sequenceEquals(this._list, other._list); |
|||
} |
|||
|
|||
public override bool Equals(object obj) { |
|||
if (object.ReferenceEquals(null, obj)) return false; |
|||
if (object.ReferenceEquals(this, obj)) return true; |
|||
if (obj.GetType() != this.GetType()) return false; |
|||
return this.Equals((_DependencyList) obj); |
|||
} |
|||
|
|||
static int _sequenceHashCode(IList list) { |
|||
unchecked { |
|||
if (list == null) { |
|||
return 0; |
|||
} |
|||
|
|||
var hashCode = 0; |
|||
for (var i = 0; i < list.Count; i++) { |
|||
var item = list[i]; |
|||
if (item is IList) { |
|||
hashCode = (hashCode * 397) ^ _sequenceHashCode((IList) item); |
|||
} else { |
|||
hashCode = (hashCode * 397) ^ (item == null ? 0 : item.GetHashCode()); |
|||
} |
|||
} |
|||
|
|||
return hashCode; |
|||
} |
|||
} |
|||
|
|||
public override int GetHashCode() { |
|||
unchecked { |
|||
return (this._type.GetHashCode() * 397) ^ _sequenceHashCode(this._list); |
|||
} |
|||
} |
|||
|
|||
public static bool operator ==(_DependencyList left, _DependencyList right) { |
|||
return object.Equals(left, right); |
|||
} |
|||
|
|||
public static bool operator !=(_DependencyList left, _DependencyList right) { |
|||
return !object.Equals(left, right); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue