Skip to content

Add integration for C# using a custom .NET Source Generator for flag calls #171

@askpt

Description

@askpt

Summary

Propose adding a new integration for C# to the CLI that leverages a custom .NET Source Generator. This generator will automatically create code for feature flag calls, streamlining flag management and usage in C# projects. We would keep the current csharp generation in the CLI but adding a new one for the source generators.

Motivation

  • Enable seamless integration of OpenFeature in C# projects by automating the generation of flag call code.
  • Reduce boilerplate and potential errors in flag usage.
  • Improve developer productivity and code maintainability.

Approach

  • Design and implement a custom .NET Source Generator that can parse feature flag definitions and generate corresponding C# code for flag calls.
  • Integrate this workflow into the OpenFeature CLI so C# developers can easily set up and use this functionality.
  • Provide documentation and usage examples for the new integration.

Tasks

  • Research .NET Source Generators and their integration points with OpenFeature.
  • Define the input format and configuration for flag definitions. I suggest using Attributes.
  • Implement the source generator logic.
  • Update the CLI to support C# integration using the generator.
  • Write documentation and sample usage code.

Additional Context

This enhancement would provide first-class support for C# developers using OpenFeature, leveraging modern .NET tooling to make flag usage safer and more efficient.

Example of generated code by CLI

using OpenFeature.Extensions.SourceGenerator;

[FeatureFlag]
private bool IsEnabled;

By leveraging source generators for the C# implementation, it would give more flexibility because anyone could potentially make use of it, even without using the CLI.

Notes

More info: https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions