/
smwwiki
/
OneScript_fork
Обзор
Документация
Войти
/
smwwiki
/
OneScript_fork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/ScriptEngine/Machine/ValueAdoptionExtensions.cs
44 строки
2 KB
EvilBeaver
Выделена отдельная папка для инфраструктуры исключений
24 июл 2023, 22:46
24 июл 2023, 22:46
d1c2e94
Код
Авторство
О чём код?
/*---------------------------------------------------------- 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 OneScript.Contexts; using OneScript.Exceptions; using OneScript.Values; using ScriptEngine.Machine.Contexts; namespace ScriptEngine.Machine { public static class ValueAdoptionExtensions { public static bool AsBoolean(this BslValue val) => (bool) val; public static DateTime AsDate(this BslValue val) => (DateTime) val; public static decimal AsNumber(this BslValue val) => (decimal) val; public static string AsString(this BslValue val) => (string) val; public static IRuntimeContextInstance AsObject(this BslValue val) => val is IRuntimeContextInstance ctx? ctx : throw BslExceptions.ValueIsNotObjectException(); public static bool AsBoolean(this IValue val) => (bool) (BslValue)val.GetRawValue(); public static DateTime AsDate(this IValue val) => (DateTime) (BslValue)val.GetRawValue(); public static decimal AsNumber(this IValue val) => (decimal) (BslValue)val.GetRawValue(); public static string AsString(this IValue val) => (string) (BslValue)val.GetRawValue(); public static IRuntimeContextInstance AsObject(this IValue val) => val.GetRawValue() is IRuntimeContextInstance ctx? ctx : throw BslExceptions.ValueIsNotObjectException(); public static object UnwrapToClrObject(this IValue value) { return ContextValuesMarshaller.ConvertToClrObject(value); } public static bool IsSkippedArgument(this IValue val) { return ReferenceEquals(val, BslSkippedParameterValue.Instance); } } }