microsoft / microsoft/Power-Fx

Parsing string into enum value

Open
#1,833 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Discussion
Dominant language
C#
Stars
3.4k
Forks
358
Avg merge
10h 34m
Merged PRs (30d)
3

Description

In my scenario I need to fill in a field in the PVA BotDesigner and ending up in the YAML to need this construct to create the ToneType enum from an input string:
Switch(Trim(Lower(Topic.SearchConfig.tone)), "friendly", ToneType.Friendly, "confident", ToneType.Confident, "empathetic", ToneType.Empathetic, "conversational", ToneType.Conversational, "motivational", ToneType.Motivational, ToneType.Professional)

While it would be a lot more convenient to be able to do this to convert a string representation of an enum into an enum value:
ToneType.parse(Topic.SearchConfig.tone)

Also parsing it this way would not need me making changes in many places once the enum might get a new entry.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no implementation files, entry points, or tests. Start by locating how Power Fx currently resolves enum references and evaluates expressions, then define the expected behavior for converting the ToneType strings shown in the examples, including unmatched input. Done means the requested string-to-enum syntax is supported and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.