[Proposal] GUID Literal
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
[(Ported from Roslyn Repo)](https://github.com/dotnet/roslyn/issues/11767)
When guid are used their value tends not to change, throughout it's usage.
If we make it a compile-time constant,
- It can be used in attributes.
- Removes the runtime parse of the GUID string.
- Compile-Time verification of the formatting.
- If the GUID is a well known one, we could offer suggestions / completion like intellisense.
[Guid.Parse](https://msdn.microsoft.com/en-us/library/system.guid.parse%28v=vs.110%29.aspx) currently supports 5 different formats.
| Specifier | Description | Format |
| --- | --- | --- |
| N | 32 digits | 00000000000000000000000000000000 |
| D | 32 digits seperated by hypens | 00000000-0000-0000-0000-0000000000000 |
| B | 32 digits seperated by hypens, enclosed in braces | {00000000-0000-0000-0000-0000000000000} |
| P | 32 digits seperated by hypens, enclosed in parentheses | (00000000-0000-0000-0000-0000000000000) |
| X | Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces | {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} |
These format should also be supported by any GUID literal.
---
**Proposed Literal Syntax (VB)**
We could extend VB's date time literal syntax `#2016/06/01#` to cover GUIDs.
``` vb.net
Dim guid0 As Guid = #00000000000000000000000000000000# ' Specifier N
Dim guid1 As Guid = #00000000-0000-0000-0000-0000000000000# ' Specifier D
Dim guid2 As Guid = #{00000000-0000-0000-0000-0000000000000}# ' Specifier B
Dim guid3 As Guid = #(00000000-0000-0000-0000-0000000000000)# ' Specified P
Dim guid4 As Guid = #{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}#
```
In an Attribute
``` vb
Imports System
Imports System.Runtime.InteropServices
_
Public Class SampleClass
' Insert class members here.
End Class
```
---
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.