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

Add --framework flag to minimize c# preprocessor directives #5122

Closed
ssnseawolf opened this issue Aug 10, 2024 · 2 comments
Closed

Add --framework flag to minimize c# preprocessor directives #5122

ssnseawolf opened this issue Aug 10, 2024 · 2 comments
Labels
Csharp Pull requests that update .net code status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close status:waiting-for-triage An issue that is yet to be reviewed or assigned type:feature New experience request

Comments

@ssnseawolf
Copy link

ssnseawolf commented Aug 10, 2024

Is your feature request related to a problem? Please describe the problem.

Kiota generates code with C# preprocessor directives based on target framework. This code is larger than necessary when the target framework is known.

Consider the following generated code from Microsoft Graph that requires #nullable:

#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
        public string? AgeGroup
        {
            get { return BackingStore?.Get<string?>("ageGroup"); }
            set { BackingStore?.Set("ageGroup", value); }
        }
#nullable restore
#else
        public string AgeGroup
        {
            get { return BackingStore?.Get<string>("ageGroup"); }
            set { BackingStore?.Set("ageGroup", value); }
        }
#endif

Client library/SDK language

Csharp

Describe the solution you'd like

The above preprocessor directive may be eliminated with an optional Kiota CLI --framework argument, mimicking the dotnet build --framework argument.

For example:
kiota generate -o x.yaml -l csharp --framework net8.0

When --framework argument is missing: Preprocessor directives are generated as they currently are. The code above is generated as-is.

When --framework argument is present: No preprocessor directives are generated since the target framework is known. For example, in the example above, if the --framework net8.0 is passed, the result would instead be:

#nullable enable
        public string? AgeGroup
        {
            get { return BackingStore?.Get<string?>("ageGroup"); }
            set { BackingStore?.Set("ageGroup", value); }
        }
#nullable restore

Additional context

Allowing the user to optionally enter a target framework reduces the amount of generated code and improves readability. Users who use Kiota-generated code across a range of .NET target environments and do not pass the proposed --framework argument would see no change in generated code.

@ssnseawolf ssnseawolf added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:feature New experience request labels Aug 10, 2024
@msgraph-bot msgraph-bot bot added the Csharp Pull requests that update .net code label Aug 10, 2024
@baywet
Copy link
Member

baywet commented Aug 12, 2024

Hi @ssnseawolf
Thank you for using kiota and for reaching out.
This is something we're unlikely to add or accept as a pull request.
Here are discussions that should provide additional background.
#3944
#3911
Let us know if you have any additional comments or questions.

@baywet baywet added the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Aug 12, 2024
@ssnseawolf
Copy link
Author

Appreciate the detailed discussion and justification in the linked issues. Kiota's good stuff - keep it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Csharp Pull requests that update .net code status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close status:waiting-for-triage An issue that is yet to be reviewed or assigned type:feature New experience request
Projects
Archived in project
Development

No branches or pull requests

2 participants