/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v2.0-alpha-1
src/OneScript.StandardLibrary/GuidWrapper.cs
79 строк
2 KB
Andrey Ovsiankin
Продолжаю удалять глобальный TypeManager
28 янв 2021, 19:25
28 янв 2021, 19:25
71f97d4
Код
Авторство
О чём код?
/*---------------------------------------------------------- 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; using System.Reflection; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; using ScriptEngine.Machine.Values; using ScriptEngine.Types; namespace OneScript.StandardLibrary { [ContextClass("УникальныйИдентификатор","UUID", TypeUUID = "B35D7F7B-DF1C-4D6C-A755-6C97A60BB345")] public class GuidWrapper : GenericValue, IObjectWrapper { Guid _value; private static readonly TypeDescriptor InstanceType; static GuidWrapper() { var attr = typeof(GuidWrapper).GetCustomAttribute<ContextClassAttribute>(); InstanceType = typeof(GuidWrapper).GetTypeFromClassMarkup(); } public GuidWrapper() { _value = Guid.NewGuid(); } public GuidWrapper(string uuidString) { _value = Guid.Parse(uuidString); } [ScriptConstructor] public static GuidWrapper Create() { return new GuidWrapper(); } [ScriptConstructor(Name = "Из строки")] public static GuidWrapper Create(IValue uuidString) { return new GuidWrapper(uuidString.AsString()); } public override TypeDescriptor SystemType => InstanceType; public override string AsString() { return _value.ToString(); } public override int CompareTo(IValue other) { GuidWrapper otherUuid = other.GetRawValue() as GuidWrapper; if (otherUuid == null) throw RuntimeException.ComparisonNotSupportedException(); return _value.CompareTo(otherUuid._value); } public override bool Equals(IValue other) { GuidWrapper otherUuid = other.GetRawValue() as GuidWrapper; if (otherUuid == null) return false; else return _value.Equals(otherUuid._value); } object IObjectWrapper.UnderlyingObject => _value; } }