From d4173b0bec63f040fcfe9f636415d556546e7fa9 Mon Sep 17 00:00:00 2001 From: samuraiGH <87191377+samuraiGH@users.noreply.github.com> Date: Sat, 28 Jun 2025 16:12:28 +0300 Subject: [PATCH] removing hard code (#3304) --- NETGenerator/NETGenerator.cs | 4 +++- NETGenerator/TypeExt.cs | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 NETGenerator/TypeExt.cs diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index b969e6600..21e74d1b9 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -1390,7 +1390,9 @@ namespace PascalABCCompiler.NETGenerator { FieldBuilder fb = cur_type.DefineField(name, helper.GetTypeReference(type).tp, FieldAttributes.Static | FieldAttributes.Public | FieldAttributes.Literal); Type t = helper.GetTypeReference(type).tp; - if (!t.Name.StartsWith("NewSet") && t.IsEnum) // SSM 05.11.24 + + // Для инстанцированных generic типов вызов .IsEnum приводит к исключению + if (!t.IsConstructedGenericType() && t.IsEnum) { if (!(t is EnumBuilder)) fb.SetConstant(Enum.ToObject(t, (constant_value as IEnumConstNode).constant_value)); diff --git a/NETGenerator/TypeExt.cs b/NETGenerator/TypeExt.cs new file mode 100644 index 000000000..7eb583fd4 --- /dev/null +++ b/NETGenerator/TypeExt.cs @@ -0,0 +1,15 @@ +using System; + +namespace PascalABCCompiler.NETGenerator +{ + internal static class TypeExt + { + /// + /// Повторяет работу свойства System.Type.IsConstructedGenericType из net fx 4.5 + /// + public static bool IsConstructedGenericType(this Type t) + { + return t.IsGenericType && !t.IsGenericTypeDefinition; + } + } +}