Пример #1
0
            public bool Equals(KeyValuePair <string, object> x, KeyValuePair <string, object> y)
            {
                object xValue = ModUtils.GetSettingUnderlyingValue(x.Value);
                object yValue = ModUtils.GetSettingUnderlyingValue(y.Value);

                return(x.Key == y.Key && EqualityComparer <object> .Default.Equals(xValue, yValue));
            }
Пример #2
0
            public bool Equals(IBindable x, IBindable y)
            {
                object xValue = x == null ? null : ModUtils.GetSettingUnderlyingValue(x);
                object yValue = y == null ? null : ModUtils.GetSettingUnderlyingValue(y);

                return(EqualityComparer <object> .Default.Equals(xValue, yValue));
            }
Пример #3
0
        public override int GetHashCode()
        {
            var hashCode = new HashCode();

            hashCode.Add(GetType());

            foreach (var setting in Settings)
            {
                hashCode.Add(ModUtils.GetSettingUnderlyingValue(setting));
            }

            return(hashCode.ToHashCode());
        }
Пример #4
0
        public void Serialize(ref MessagePackWriter writer, Dictionary <string, object> value, MessagePackSerializerOptions options)
        {
            var primitiveFormatter = PrimitiveObjectFormatter.Instance;

            writer.WriteArrayHeader(value.Count);

            foreach (var kvp in value)
            {
                var stringBytes = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes(kvp.Key));
                writer.WriteString(in stringBytes);

                primitiveFormatter.Serialize(ref writer, ModUtils.GetSettingUnderlyingValue(kvp.Value), options);
            }
        }
Пример #5
0
        public APIMod(Mod mod)
        {
            Acronym = mod.Acronym;

            foreach (var(_, property) in mod.GetSettingsSourceProperties())
            {
                var bindable = (IBindable)property.GetValue(mod);

                if (!bindable.IsDefault)
                {
                    Settings.Add(property.Name.Underscore(), ModUtils.GetSettingUnderlyingValue(bindable));
                }
            }
        }
Пример #6
0
        public bool Equals(Mod other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(GetType() == other.GetType() &&
                   this.GetSettingsSourceProperties().All(pair =>
                                                          EqualityComparer <object> .Default.Equals(
                                                              ModUtils.GetSettingUnderlyingValue(pair.Item2.GetValue(this)),
                                                              ModUtils.GetSettingUnderlyingValue(pair.Item2.GetValue(other)))));
        }
Пример #7
0
 public int GetHashCode(IBindable obj) => ModUtils.GetSettingUnderlyingValue(obj).GetHashCode();
Пример #8
0
 public int GetHashCode(KeyValuePair <string, object> obj) => HashCode.Combine(obj.Key, ModUtils.GetSettingUnderlyingValue(obj.Value));