Very difficult to work with enums and option sets
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- backend-api-design
Research direction
Start by tracing the existing OptionSet and enum-marshalling APIs referenced in the issue, including OptionSet, OptionSetValue, and FormulaValue. Compare their current construction and value-selection paths with the proposed generic FromEnum and GetValue entry points. Done means enum-backed option sets can be created and values selected with compile-time checking, with relevant coverage added for the new API.
Written by the indexing model from the issue text.
Description
I have data in my app which contains standard enumerations. I want to expose these as OptionSets that users can interact with via formulas. Right now, to create the option set and a reference to one of the option set values I have to do the following:
var optionSet = new OptionSet("StateCode", DisplayNameUtility.MakeUnique(new Dictionary<string, string>()
{
{ nameof(msdyn_exportcontrolcode_statecode.Active), nameof(msdyn_exportcontrolcode_statecode.Active) },
{ nameof(msdyn_exportcontrolcode_statecode.Inactive), nameof(msdyn_exportcontrolcode_statecode.Inactive) },
}));
Microsoft.PowerFx.Types.OptionSetValue stateOptionSetValue = null;
if (StateCodeOptionSet.OptionSet.TryGetValue(new Microsoft.PowerFx.Core.Utils.DName(Enum.GetName(typeof(msdyn_exportcontrolcode_statecode), State)), out stateOptionSetValue))
{
myFields.Add(new NamedValue("State", stateOptionSetValue));
}
This isn't very discoverable. Since enum and option set marshalling is extremely common this should be a lot easier and give compile time checking for future changes, as well as let you explicitly pick a value out of the list without having to do TryParse. For example:
enum Fruit { apple , ... }
OptionSet os = OptionSet.FromEnum();
FormulaValue fv = os.GetValue(Fruit.Apple); // strongly typed OS.GetValue(T value)
- Dominant language
- C#
- Stars
- 3.4k
- Forks
- 358
- Avg merge
- 10h 34m
- Merged PRs (30d)
- 3
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/Power-Fx
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 5/5 Over a week Newbie friendliness 32/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
All issues in microsoft/Power-Fx
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100