From 95d57afdec3104c02068a29a96033f522c4e8760 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 19 Jul 2026 10:49:48 -0700 Subject: [PATCH] =?UTF-8?q?feat(objects):=20ExtractCtors=20=E2=80=94=20con?= =?UTF-8?q?structible=20ctor=20arguments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Objects/ObjectIntrospectionCtorsTests.cs | 24 ++++++++++++++ .../Object Creation/ObjectIntrospection.cs | 33 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Projects/UOContent.Tests/Tests/Commands/Objects/ObjectIntrospectionCtorsTests.cs diff --git a/Projects/UOContent.Tests/Tests/Commands/Objects/ObjectIntrospectionCtorsTests.cs b/Projects/UOContent.Tests/Tests/Commands/Objects/ObjectIntrospectionCtorsTests.cs new file mode 100644 index 000000000..fcdaed07c --- /dev/null +++ b/Projects/UOContent.Tests/Tests/Commands/Objects/ObjectIntrospectionCtorsTests.cs @@ -0,0 +1,24 @@ +using System.Linq; +using Server.Commands; +using Server.Items; +using Xunit; + +namespace UOContent.Tests.Commands.Objects; + +[Collection("Sequential UOContent Tests")] +public class ObjectIntrospectionCtorsTests +{ + [Fact] + public void ExtractCtors_lists_both_constructible_runebook_overloads() + { + // Runebook has [Constructible] Runebook() and [Constructible] Runebook(int maxCharges). + var ctors = ObjectIntrospection.ExtractCtors(typeof(Runebook)); + + Assert.Equal(2, ctors.Count); + Assert.Contains(ctors, c => c.Parameters.Count == 0); + + var parameterized = Assert.Single(ctors, c => c.Parameters.Count == 1); + Assert.Equal("maxCharges", parameterized.Parameters[0].Name); + Assert.Equal("int", parameterized.Parameters[0].Type); + } +} diff --git a/Projects/UOContent/Commands/Object Creation/ObjectIntrospection.cs b/Projects/UOContent/Commands/Object Creation/ObjectIntrospection.cs index 4d7a0222e..357909c77 100644 --- a/Projects/UOContent/Commands/Object Creation/ObjectIntrospection.cs +++ b/Projects/UOContent/Commands/Object Creation/ObjectIntrospection.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Reflection; using Server.Items; namespace Server.Commands; @@ -57,4 +59,35 @@ public static class ObjectIntrospection throw new ArgumentException($"{type} is neither Item nor Mobile.", nameof(type)); } + + public static List ExtractCtors(Type type) + { + var docs = new List(); + + foreach (var ctor in type.GetConstructors()) + { + if (!Attributes.IsConstructible(ctor, AccessLevel.Developer)) + { + continue; + } + + var doc = new CtorDoc(); + foreach (var p in ctor.GetParameters()) + { + doc.Parameters.Add( + new ParamDoc + { + Name = p.Name, + Type = ObjectNaming.FriendlyTypeName(p.ParameterType), + Default = p.HasDefaultValue ? p.DefaultValue?.ToString() ?? "null" : null, + IsParams = p.IsDefined(typeof(ParamArrayAttribute), false) + } + ); + } + + docs.Add(doc); + } + + return docs; + } }