Skip to content

Commit 99486de

Browse files
committed
native: получить значение перечисления
1 parent e07faec commit 99486de

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/OneScript.Core/TypeUtils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static bool IsNumeric(this Type type)
1818
switch (Type.GetTypeCode(type))
1919
{
2020
case TypeCode.Int32:
21+
return !type.IsEnum;
2122
case TypeCode.Decimal:
2223
case TypeCode.UInt32:
2324
case TypeCode.Int64:

src/OneScript.Native/Compiler/ExpressionHelpers.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,24 @@ private static Expression TryFindConversionOp(Expression value, Type targetType)
267267

268268
return DowncastDecimal(decimalNum, targetType);
269269
}
270+
else if (targetType.IsEnum)
271+
{
272+
Type generic = typeof(ClrEnumValueWrapper<>);
273+
var wrapperType = generic.MakeGenericType(new[]{targetType});
274+
try
275+
{
276+
var wrapper = Expression.Convert(value, wrapperType);
277+
return Expression.Property(wrapper,"UnderlyingValue");
278+
}
279+
catch (InvalidOperationException)
280+
{
281+
throw new NativeCompilerException(
282+
BilingualString.Localize(
283+
$"Преобразование {value.Type} в тип {targetType} недоступно",
284+
$"Conversion from {value.Type} to {targetType} is unavailable")
285+
);
286+
}
287+
}
270288
else
271289
{
272290
var conversion = TryConvertBslValueToPrimitiveType(value, targetType);

0 commit comments

Comments
 (0)