removing hard code (#3304)

This commit is contained in:
samuraiGH 2025-06-28 16:12:28 +03:00 committed by GitHub
parent 0972d09837
commit d4173b0bec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -1390,7 +1390,9 @@ namespace PascalABCCompiler.NETGenerator
{ {
FieldBuilder fb = cur_type.DefineField(name, helper.GetTypeReference(type).tp, FieldAttributes.Static | FieldAttributes.Public | FieldAttributes.Literal); FieldBuilder fb = cur_type.DefineField(name, helper.GetTypeReference(type).tp, FieldAttributes.Static | FieldAttributes.Public | FieldAttributes.Literal);
Type t = helper.GetTypeReference(type).tp; 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)) if (!(t is EnumBuilder))
fb.SetConstant(Enum.ToObject(t, (constant_value as IEnumConstNode).constant_value)); fb.SetConstant(Enum.ToObject(t, (constant_value as IEnumConstNode).constant_value));

15
NETGenerator/TypeExt.cs Normal file
View file

@ -0,0 +1,15 @@
using System;
namespace PascalABCCompiler.NETGenerator
{
internal static class TypeExt
{
/// <summary>
/// Повторяет работу свойства System.Type.IsConstructedGenericType из net fx 4.5
/// </summary>
public static bool IsConstructedGenericType(this Type t)
{
return t.IsGenericType && !t.IsGenericTypeDefinition;
}
}
}