Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider splitting into two language options for different use cases #7

Open
GinoCanessa opened this issue Jul 2, 2020 · 0 comments
Labels
c# basic Specific to export of Language CSharpBasic enhancement New feature or request

Comments

@GinoCanessa
Copy link
Contributor

I could imagine two variants of the codegen: one optimized for programmer-friendliness, the other optimized for performance. Take this class for example:

  public class DataRequirementSort : Element {
    [JsonProperty("direction")]
    public string Direction { get; set; }
    [JsonProperty("_direction")]
    public Element _Direction { get; set; }
    [JsonProperty("path")]
    public string Path { get; set; }
    [JsonProperty("_path")]
    public Element _Path { get; set; }
  }

For developer-friendliness, it might look like this:

public class DataRequirementSort : Element 
{
    [JsonProperty("direction")]
    public Element<string> Direction { get; set; }
    [JsonProperty("path")]
    public Element<string> Path { get; set; }
}

internal class Element<T>
{
    public Element<string> Id { get; set; }
    public Extension[] Extensions { get; set; }
    public T Value { get; set; }
}

For server-side performance, it might look more like this, given that extensions on primitive types are probably exceedingly rare:

internal class DataRequirementSort : Element
{
    private Dictionary<int, Element> _primitiveElements;

    [JsonProperty("direction")]
    public string Direction { get; set; }
    
    [JsonProperty("_direction")]
    public Element _Direction
    {
        get => GetPrimitiveElement(0);
        set => SetPrimitiveElement(0, value);
    }
    
    [JsonProperty("path")]
    public string Path { get; set; }
    
    [JsonProperty("_path")]
    public Element _Path
    {
        get => GetPrimitiveElement(0);
        set => SetPrimitiveElement(0, value);
    }

    private Element GetPrimitiveElement(int id)
    {
        Element value = null;
        _primitiveElements?.TryGetValue(id, out value);
        return value;
    }

    private void SetPrimitiveElement(int id, Element value)
    {
        (_primitiveElements ?? (_primitiveElements = new Dictionary<int, Element>()))[id] = value;
    }
}

Originally posted by @johnstairs in #2 (comment)

@GinoCanessa GinoCanessa added c# basic Specific to export of Language CSharpBasic enhancement New feature or request labels Jul 2, 2020
GinoCanessa pushed a commit that referenced this issue May 17, 2021
…resourcereference-on-choice-types

Produce ResourceReference attributes for choice types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c# basic Specific to export of Language CSharpBasic enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant