I have created enums below in PowerShell. However, if I have a dot in the enum name (for example, "Name.A") then Add-Type would return an error. How do I go about it? I don't want to remove the dot from "Name.A".
$TypeEnum = "
namespace Types {
public enum Id {
Name.A = 1,
NameB = 2,
NameC = 3
}
}"
Add-Type -TypeDefinition $TypeEnum -Language CSharpVersion3
([Types.Id]::'Name.A').value__
Here is the error that I get:
Add-Type : c:\Users\User1\AppData\Local\Temp\ab0z5i1y.0.cs(4) : } expected c:\Users\User1\AppData\Local\Temp\ab0z5i1y.0.cs(3) :
public enum Id { c:\Users\User1\AppData\Local\Temp\ab0z5i1y.0.cs(4) : >>> Name.A = 1, c:\Users\User1\AppData\Local\Temp\ab0z5i1y.0.cs(5) :
NameB = 2, At line:10 char:1 + Add-Type -TypeDefinition $TypeEnum -Language CSharpVersion3 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (c:\Users\User1...513: } expected:CompilerError) [Add-Type], Exception + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : c:\Users\User1\AppData\Local\Temp\ab0z5i1y.0.cs(8) : Type or namespace definition, or end-of-file expected c:\Users\User1\AppData\Local\Temp\ab0z5i1y.0.cs(7) : }
c:\Users\User1\AppData\Local\Temp\ab0z5i1y.0.cs(8) : >>> } At line:10 char:1 + Add-Type -TypeDefinition $TypeEnum -Language CSharpVersion3 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (c:\Users\User1...f-file expected:CompilerError) [Add-Type], Exception + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Cannot add type. There were compilation errors. At line:10 char:1 + Add-Type -TypeDefinition $TypeEnum -Language CSharpVersion3 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException + FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand Unable to find type [Types.Id]: make sure that the assembly containing this type is loaded. At line:12 char:1 + ([Types.Id]::'Name.A').value__ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Types.Id:TypeName) [], RuntimeException + FullyQualifiedErrorId : TypeNotFound
Name.A
toNameA
. Periods are not allowed in identifiers in C#. Why do you not want to remove the dot? – Chris Dunaway