/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v2.0-alpha-1
src/ScriptEngine/Machine/GenericIValueComparer.cs
50 строк
1 KB
Andrey Ovsiankin
Полностью переделана работа с типами (начало).
26 янв 2021, 17:56
26 янв 2021, 17:56
5d1c262
Код
Авторство
О чём код?
/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ using System.Collections.Generic; using ScriptEngine.Machine.Contexts; namespace ScriptEngine.Machine { public class GenericIValueComparer : IEqualityComparer<IValue>, IComparer<IValue> { public bool Equals(IValue x, IValue y) { return x.Equals(y); } public int GetHashCode(IValue obj) { object CLR_obj; if (obj.DataType == DataType.Undefined) return obj.GetHashCode(); try { CLR_obj = ContextValuesMarshaller.ConvertToCLRObject(obj); } catch (ValueMarshallingException) { CLR_obj = obj; } return CLR_obj.GetHashCode(); } public int Compare(IValue x, IValue y) { if (ReferenceEquals(x, default) && ReferenceEquals(y, default)) return 0; if (x.SystemType == y.SystemType) return x.CompareTo(y); else return x.AsString().CompareTo(y.AsString()); } } }