From 685fbc146edecd6dbdf19686d9684f167310236f Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 19 Jul 2026 10:54:40 -0700 Subject: [PATCH] =?UTF-8?q?feat(objects):=20ExtractProperties=20=E2=80=94?= =?UTF-8?q?=20[CommandProperty]=20props=20with=20enum=20expansion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add ObjectIntrospection.ExtractProperties(Type) to extract public instance properties carrying [CommandProperty] attribute, including inherited ones. Properties include type via ObjectNaming.FriendlyTypeName, read/write access levels, readOnly flag, and enum values expanded via Enum.GetNames. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../ObjectIntrospectionPropertiesTests.cs | 23 ++++++++++++++ .../Object Creation/ObjectIntrospection.cs | 30 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Projects/UOContent.Tests/Tests/Commands/Objects/ObjectIntrospectionPropertiesTests.cs diff --git a/Projects/UOContent.Tests/Tests/Commands/Objects/ObjectIntrospectionPropertiesTests.cs b/Projects/UOContent.Tests/Tests/Commands/Objects/ObjectIntrospectionPropertiesTests.cs new file mode 100644 index 000000000..efda9a929 --- /dev/null +++ b/Projects/UOContent.Tests/Tests/Commands/Objects/ObjectIntrospectionPropertiesTests.cs @@ -0,0 +1,23 @@ +using System.Linq; +using Server.Commands; +using Server.Items; +using Xunit; + +namespace UOContent.Tests.Commands.Objects; + +[Collection("Sequential UOContent Tests")] +public class ObjectIntrospectionPropertiesTests +{ + [Fact] + public void ExtractProperties_includes_inherited_item_command_properties() + { + var props = ObjectIntrospection.ExtractProperties(typeof(Runebook)); + + var hue = Assert.Single(props, p => p.Name == "Hue"); + Assert.Equal("int", hue.Type); + + var lootType = Assert.Single(props, p => p.Name == "LootType"); + Assert.NotNull(lootType.EnumValues); + Assert.Contains("Blessed", lootType.EnumValues); + } +} diff --git a/Projects/UOContent/Commands/Object Creation/ObjectIntrospection.cs b/Projects/UOContent/Commands/Object Creation/ObjectIntrospection.cs index 357909c77..f264a76f0 100644 --- a/Projects/UOContent/Commands/Object Creation/ObjectIntrospection.cs +++ b/Projects/UOContent/Commands/Object Creation/ObjectIntrospection.cs @@ -90,4 +90,34 @@ public static class ObjectIntrospection return docs; } + + public static List ExtractProperties(Type type) + { + var docs = new List(); + + var props = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); + foreach (var p in props) + { + var attr = p.GetCustomAttribute(true); + if (attr == null) + { + continue; + } + + var pt = p.PropertyType; + docs.Add( + new PropertyDoc + { + Name = p.Name, + Type = ObjectNaming.FriendlyTypeName(pt), + ReadLevel = attr.ReadLevel.ToString(), + WriteLevel = attr.WriteLevel.ToString(), + ReadOnly = attr.ReadOnly || !p.CanWrite, + EnumValues = pt.IsEnum ? Enum.GetNames(pt) : null + } + ); + } + + return docs; + } }