From 35c6ba5002afaeabf22351da52c5ae2d0dabf75f Mon Sep 17 00:00:00 2001 From: Daniel Cronqvist Date: Sat, 16 Nov 2024 18:35:21 +0100 Subject: [PATCH] Add storageType parameter to FromEnum, default value is consistent with Tiled --- .../Properties/CustomTypes/CustomEnumDefinition.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/DotTiled/Properties/CustomTypes/CustomEnumDefinition.cs b/src/DotTiled/Properties/CustomTypes/CustomEnumDefinition.cs index 72593d9..b0d6e88 100644 --- a/src/DotTiled/Properties/CustomTypes/CustomEnumDefinition.cs +++ b/src/DotTiled/Properties/CustomTypes/CustomEnumDefinition.cs @@ -51,8 +51,9 @@ public class CustomEnumDefinition : ICustomTypeDefinition /// Creates a custom enum definition from the specified enum type. /// /// + /// The storage type of the custom enum. Defaults to to be consistent with Tiled. /// - public static CustomEnumDefinition FromEnum() where T : Enum + public static CustomEnumDefinition FromEnum(CustomEnumStorageType storageType = CustomEnumStorageType.String) where T : Enum { var type = typeof(T); var isFlags = type.GetCustomAttributes(typeof(FlagsAttribute), false).Length != 0; @@ -60,7 +61,7 @@ public class CustomEnumDefinition : ICustomTypeDefinition return new CustomEnumDefinition { Name = type.Name, - StorageType = CustomEnumStorageType.Int, + StorageType = storageType, Values = Enum.GetNames(type).ToList(), ValueAsFlags = isFlags }; @@ -69,8 +70,10 @@ public class CustomEnumDefinition : ICustomTypeDefinition /// /// Creates a custom enum definition from the specified enum type. /// + /// The enum type to create a custom enum definition from. + /// The storage type of the custom enum. Defaults to to be consistent with Tiled. /// - public static CustomEnumDefinition FromEnum(Type type) + public static CustomEnumDefinition FromEnum(Type type, CustomEnumStorageType storageType = CustomEnumStorageType.String) { if (!type.IsEnum) throw new ArgumentException("Type must be an enum.", nameof(type)); @@ -80,7 +83,7 @@ public class CustomEnumDefinition : ICustomTypeDefinition return new CustomEnumDefinition { Name = type.Name, - StorageType = CustomEnumStorageType.Int, + StorageType = storageType, Values = Enum.GetNames(type).ToList(), ValueAsFlags = isFlags };