Skip to content

No way to rename enum variants #104

@Lynnesbian

Description

@Lynnesbian

The TOML I want to parse looks like this:

[podcast.example]
on_error = "skip_episode"

I tried to parse it into a model with an enum, like this:

public enum OnError {
	SkipPodcast,
	SkipEpisode,
	Abort,
}

Tomlyn expects to read values as PascalCase rather than snake_case, causing an error:

Error: (45,1) : error : Exception while trying to convert System.String to type GrabCastSharp.OnError. Reason: Requested value 'skip_episode' was not found.
(45,1) : error : The property value of type System.String couldn't be converted to System.Nullable`1[GrabCastSharp.OnError] for the property GrabCastSharp.Podcast/on_error

I tried to use DataMember annotations to rename the enum variants, but it had no effect:

public enum OnError {
	[DataMember(Name = "skip_podcast")]
	SkipPodcast,
	[DataMember(Name = "skip_episode")]
	SkipEpisode,
	[DataMember(Name = "abort")]
	Abort,
}

Is there a way to achieve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions