Skip to content

Commit

Permalink
Added ToLowerInvariant and ToUpperInvariant cases to MissingValueHand…
Browse files Browse the repository at this point in the history
…ling
  • Loading branch information
yugabe committed Aug 31, 2024
1 parent 3fa5139 commit 2c1b538
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ Defines the behavior that is executed when a defined enum value has no associate
|`SnakeCasing`|Returns the enum name as a `snake_cased_string`. Assumes the name is in PascalCase.|
|`RawValueToString`|The raw constant value itself is returned by calling `object.ToString()` on the value.|
|`EmptyString`|Returns an empty string. This is useful if you want to implement a wrapper around the generated method and handle this case in user code.|
|`ToLowerInvariant`|Returns the enum name lowercased (culture invariant).|
|`ToUpperInvariant`|Returns the enum name uppercased (culture invariant).|

</details>

Expand Down
6 changes: 5 additions & 1 deletion src/EnumValues.Core/MissingValueHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ public enum MissingValueHandling
/// <summary>The raw constant value itself is returned by calling <see cref="object.ToString()"/> on the value.</summary>
RawValueToString,
/// <summary>Returns an empty string. This is useful if you want to implement a wrapper around the generated method and handle this case in user code.</summary>
EmptyString
EmptyString,
/// <summary>Returns the enum name lowercased (culture invariant).</summary>
ToLowerInvariant,
/// <summary>Returns the enum name uppercased (culture invariant).</summary>
ToUpperInvariant
}
2 changes: 2 additions & 0 deletions src/EnumValues/Generator/Models/EnumValueCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public static ImmutableArray<EnumValueCase> CreateMany(INamedTypeSymbol enumType
{
MissingValueHandling.ThrowMissingValueException => null,
MissingValueHandling.ToString => symbol.Name,
MissingValueHandling.ToLowerInvariant => symbol.Name.ToLowerInvariant(),
MissingValueHandling.ToUpperInvariant => symbol.Name.ToUpperInvariant(),
MissingValueHandling.RawValueToString => symbol.ConstantValue?.ToString() ?? "",
MissingValueHandling.EmptyString => "",
_ => CodeText.AlterCasing(symbol.Name, missingValueHandling)
Expand Down

0 comments on commit 2c1b538

Please sign in to comment.