I'm working with some auto-generated code from openapi-generator-cli, and I've hit a snag with an enum that's throwing errors. It appears that PowerShell (PS) doesn't accept integers as enum labels. I'm trying to figure out how to define an enum that uses string representations of integers instead. Here's what I've got so far:
```powershell
enum SerialInterfaceV130BitRate {
# enum value: "1200"
1200
# enum value: "2400"
2400
# enum value: "4800"
4800
# enum value: "9600"
9600
# enum value: "19200"
19200
# enum value: "38400"
38400
# enum value: "57600"
57600
# enum value: "115200"
115200
# enum value: "230400"
230400
}
```
When I try to run it, I get a ParserError stating there's a missing closing '}' in my block, and I've tried changing the format to use quotes around the integers but that hasn't worked either. How can I fix this?
4 Answers
Remember that enum labels in .NET must follow naming conventions, which means they can't just be numbers. If you want a flexible solution, consider using an array instead of an enum. A `HashSet` might work better if you need a strongly typed collection. Check out its documentation for more guidance!
How are you planning to use this enum? If you're just looking to represent these values, consider casting the enum to an integer instead of trying to redefine it. But based on your example, it sounds like the main issue is with how you're defining it.
You might be running into naming issues. Enum identifiers can't start with a number in C#, so you'll need to change your enum names to start with a letter. Try something like `V1200`, `V2400`, etc.
Got it! I'll adjust the naming and see if that helps.
You could use `.value__` to retrieve the int value of an enum. Here's an example of how you might structure it:
```powershell
enum SerialInterfaceV130BitRate {
V1200 = 1200
V2400 = 2400
V4800 = 4800
V9600 = 9600
V19200 = 19200
V38400 = 38400
V57600 = 57600
V115200 = 115200
V230400 = 230400
}
$ByName = [SerialInterfaceV130BitRate]::V230400
$ByInt32 = [SerialInterfaceV130BitRate] 230400
$AsInt = ([SerialInterfaceV130BitRate] 230400).value__
```
From there, you can play around with it as needed!
That makes sense! Just to clarify, if you do something like `[SerialInterfaceV130BitRate] 1200 -eq 1200`, it should return true without needing to convert it to int first, right?

I've tried a few variations, but I'm still getting that parser error, particularly when I try to put quotes around the numbers. It’s a bit frustrating.