refactor(Hi.Sample): convert DemoBuildMachineTool to Reg(XFactory factory=null)

Static ctor rewritten as public static void Reg(XFactory factory = null).

Part of the workspace-wide ~270-class XFactory refactor; see HiGeom commit
for the XFactory instance refactor and full pattern rationale.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
iamboss 2026-05-24 10:34:11 +08:00
parent 7e2a4b116a
commit 05ada6189b

View File

@ -23,9 +23,15 @@ namespace Sample.MachineTool
/// </remarks> /// </remarks>
public class DemoBuildMachineTool : IGetCodeXyzabcMachineTool public class DemoBuildMachineTool : IGetCodeXyzabcMachineTool
{ {
static DemoBuildMachineTool() /// <summary>
/// Registers this type's deserializer with the given <see cref="XFactory"/>
/// (or <see cref="XFactory.Default"/> when <paramref name="factory"/> is
/// <c>null</c>). Idempotent.
/// </summary>
public static void Reg(XFactory factory = null)
{ {
XFactory.Generators.Add(XName, (xml, baseDirectory, relFile, progress, res) => new DemoBuildMachineTool()); factory ??= XFactory.Default;
factory.Generators.TryAdd(XName, (xml, baseDirectory, relFile, progress, res) => new DemoBuildMachineTool());
} }
/// <summary> /// <summary>
/// Generates an XYZ-ABC machine tool instance from embedded resources. /// Generates an XYZ-ABC machine tool instance from embedded resources.