Skip to content

Compositional creation for allOf types #646

@idg10

Description

@idg10

I have an application that produces various forms out JSON output where there is some overlap between the property set. I'm using a mix-in-like approach, so one type might start like this:

    "transitiveFrameworkReferenceTestRun": {
      "allOf": [
        { "$ref": "./CommonSchema.json#/$defs/testRun" },
        { "$ref": "./CommonSchema.json#/$defs/bloatTestResults" }
      ],
      "properties": {
...

another might

    "extensionMethodsWorkaroundTestRun": {
      "allOf": [
        { "$ref": "./CommonSchema.json#/$defs/testRun" },
        { "$ref": "./CommonSchema.json#/$defs/buildResults" },
        { "$ref": "./CommonSchema.json#/$defs/bloatTestResults" }
      ],
      "properties": {

and another is like this:

    "issue97TestRun": {
      "$ref": "./CommonSchema.json#/$defs/testRun",
      "properties": {

So in this particular app, it happens that all of these ...TestRun types are all instances of testRun. And then there are some other common sets of properties that I want to appear in some but not all of these types.

This works, but the thing I would like to be able to do in C# is build up some of these allOf types from the components. Suppose I already have a TestRun and BloatTestResults in hand, I'd like to be able to supply these directly when building a TransitiveFrameworkReferenceTestRun.

Currently, the TransitiveFrameworkReferenceTestRun.Create method effectively requires me to deconstruct and reassemble the things:

TransitiveFrameworkReferenceTestRun.Create(
  deployedWindowsForms: bloatTestResults.DeployedWindowsForms,
  deployedWpf: bloatTestResults.DeployedWpf,
  testRunDateTime: testRun.TestRunDateTime,
  testRunId: testRun.TestRunId,
  ... properties defined directly by transitiveFrameworkReferenceTestRun
);

It's not a huge issue, and I don't expect we'd gain a performance benefit from being able to assemble it from the larger chunks. Even deconstructing and reconstructing like this will result in a TransitiveFrameworkReferenceTestRun that is effectively pointing to the same data as the inputs. But it would be convenient to be able to just plug the bigger pieces together:

TransitiveFrameworkReferenceTestRun.Create(
  bloatTestResults,
  testRun,
  ... properties defined directly by transitiveFrameworkReferenceTestRun
);

Possibly there is already some way of doing this that I've not discovered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions