Skip to content

Commit efaba20

Browse files
dmealingclaude
andcommitted
refactor(csharp): simplify loader-unification code
Tightens the recently-landed loader unification (DirectorySource, UriSource, MetaDataLoader.FromDirectory/FromUris/FromString factories) without touching any public name or behavior. All 526 tests still pass. - Centralize extension→MetaDataFormat inference in MetaDataFormats.InferFromExtension (MetaDataSource.cs), eliminating the duplicated yaml/yml ternary in both FileSource and UriSource. - Collapse MetaDataLoader's three-step constructor chain to one zero-arg ctor plus the full ctor with default args (freeze=true, strict=false); the intermediate (TypeRegistry) overload is still source-compatible via defaults. - Merge two back-to-back `if (root is not null)` blocks in Load() around the super-resolution + validation-pass section into a single guarded block. - Update server/csharp/README.md Loader/ inventory to reflect the rename (InMemorySource → InMemoryStringSource), the new DirectorySource + UriSource, the FromDirectory/FromUris/FromString factories, and the retirement of FileMetaDataLoader. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent df1628c commit efaba20

5 files changed

Lines changed: 20 additions & 31 deletions

File tree

server/csharp/MetaObjects/Loader/FileSource.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ public FileSource(string path)
2222
{
2323
FilePath = path;
2424
Id = System.IO.Path.GetFileName(path);
25-
string ext = System.IO.Path.GetExtension(path);
26-
Format = ext.Equals(".yaml", StringComparison.OrdinalIgnoreCase)
27-
|| ext.Equals(".yml", StringComparison.OrdinalIgnoreCase)
28-
? MetaDataFormat.Yaml
29-
: MetaDataFormat.Json;
25+
Format = MetaDataFormats.InferFromExtension(path);
3026
}
3127

3228
/// <summary>

server/csharp/MetaObjects/Loader/MetaDataLoader.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,11 @@ public class MetaDataLoader
4444
// Constructors
4545
// -------------------------------------------------------------------------
4646

47-
/// <summary>
48-
/// Construct with the default core-types registry, freeze=true, strict=false.
49-
/// </summary>
47+
/// <summary>Construct with the default core-types registry, freeze=true, strict=false.</summary>
5048
public MetaDataLoader()
5149
: this(DefaultRegistry()) { }
5250

53-
/// <summary>
54-
/// Construct with a custom registry, freeze=true, strict=false.
55-
/// </summary>
56-
public MetaDataLoader(TypeRegistry registry)
57-
: this(registry, freeze: true, strict: false) { }
58-
59-
/// <summary>Full constructor — registry, freeze, strict all configurable.</summary>
51+
/// <summary>Full constructor — registry required; freeze and strict configurable (defaults: freeze=true, strict=false).</summary>
6052
public MetaDataLoader(TypeRegistry registry, bool freeze = true, bool strict = false)
6153
{
6254
_registry = registry;
@@ -254,21 +246,17 @@ public LoadResult Load(IReadOnlyList<IMetaDataSource> sources)
254246
}
255247

256248
// After the merge loop, BEFORE freeze — validation passes.
257-
258-
// Pass 1: resolveDeferredSupers — resolve cross-file extends refs against the full merged root.
259249
if (root is not null)
260250
{
251+
// Pass 1: resolveDeferredSupers — resolve cross-file extends refs against the full merged root.
261252
var failures = SuperResolve.ResolveDeferredSupers(root);
262253
foreach (var failure in failures)
263254
{
264255
errors.Add(new MetaError(
265256
$"the SuperClass '{failure.Ref}' does not exist (referenced by {failure.NodeFqn})",
266257
ErrorCode.ERR_UNRESOLVED_SUPER));
267258
}
268-
}
269259

270-
if (root is not null)
271-
{
272260
// Pass 2: subtype rules (value must not have primary identity; entity should have one)
273261
var subtypeResult = ValidationPasses.ValidateSubtypeRules(root);
274262
errors.AddRange(subtypeResult.Errors);

server/csharp/MetaObjects/Loader/MetaDataSource.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ public interface IMetaDataSource
2121
string Read();
2222
}
2323

24+
/// <summary>Shared helpers for <see cref="IMetaDataSource"/> implementations.</summary>
25+
internal static class MetaDataFormats
26+
{
27+
/// <summary>Infer <see cref="MetaDataFormat"/> from a path/URI extension. Unknown → JSON.</summary>
28+
internal static MetaDataFormat InferFromExtension(string path)
29+
{
30+
string ext = System.IO.Path.GetExtension(path);
31+
return ext.Equals(".yaml", StringComparison.OrdinalIgnoreCase)
32+
|| ext.Equals(".yml", StringComparison.OrdinalIgnoreCase)
33+
? MetaDataFormat.Yaml
34+
: MetaDataFormat.Json;
35+
}
36+
}
37+
2438
/// <summary>A metadata source backed by an in-memory string.</summary>
2539
public sealed class InMemoryStringSource : IMetaDataSource
2640
{

server/csharp/MetaObjects/Loader/UriSource.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public UriSource(Uri uri, MetaDataFormat? format = null)
3131
{
3232
Uri = uri ?? throw new ArgumentNullException(nameof(uri));
3333
Id = uri.ToString();
34-
Format = format ?? InferFormatFromExtension(uri.AbsolutePath);
34+
Format = format ?? MetaDataFormats.InferFromExtension(uri.AbsolutePath);
3535
}
3636

3737
public string Read()
@@ -50,13 +50,4 @@ public string Read()
5050

5151
throw new NotSupportedException($"Unsupported URI scheme '{Uri.Scheme}' on {Uri}");
5252
}
53-
54-
private static MetaDataFormat InferFormatFromExtension(string path)
55-
{
56-
string ext = Path.GetExtension(path);
57-
return ext.Equals(".yaml", StringComparison.OrdinalIgnoreCase)
58-
|| ext.Equals(".yml", StringComparison.OrdinalIgnoreCase)
59-
? MetaDataFormat.Yaml
60-
: MetaDataFormat.Json;
61-
}
6253
}

server/csharp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The test suite includes per-fixture `Lint` and `Conformance` theories over the s
3232
- `CoreAttrSchemas.cs`, `CoreTypes.cs` — the `metaobjects-core-types` provider
3333
- `Parser.cs`, `SuperResolve.cs`, `SerializerJson.cs`
3434
- `YamlDesugar.cs`, `ParserYaml.cs` — YAML authoring front-end (ADR-0006)
35-
- `Loader/``IMetaDataSource`, `InMemorySource`, `FileSource`, `MetaDataLoader`, `FileMetaDataLoader`, `ValidationPasses`
35+
- `Loader/``IMetaDataSource`, `InMemoryStringSource`, `FileSource`, `DirectorySource`, `UriSource`, `MetaDataLoader` (with `FromDirectory`/`FromUris`/`FromString` static factories), `ValidationPasses`
3636
- `MetaObjects.Conformance.Tests/` — xUnit test project + conformance harness
3737
- `ConformanceAdapter.cs`, `FixtureDiscovery.cs`, `OperationScript.cs`, `FixtureLint.cs`, `Navigator.cs`, `CapabilityBinding.cs`, `Result.cs`, `ExpectedFailures.cs`, `conformance-expected-failures.json`, `ConformanceTests.cs`
3838
- `YamlConformanceTests.cs`, `YamlDesugarTests.cs`, `yaml-conformance-expected-failures.json` — YAML conformance + unit tests

0 commit comments

Comments
 (0)