How can such a function be created? (How do the framework do it for Chr) Or why is it not possible, but possible in the framework?
Example of consts declared from function:
''' <summary>Carriage Return \r 13 0xD</summary>
Public Const Cr As Char = ChrW(&HD)
''' <summary>Line Feed \n 10 0xA</summary>
Public Const Lf As Char = ChrW(&HA)
So it should be possible to create similar functions ex:
Public Const Magic As String = "Magic" ' ok
Public Const lcMagic As String = Magic.ToLower ' not ok - wanted to avoiding potential bugs if Magic is ever changed.
Public Const Magic2 As String = functionGeneratingLongButStaticString()
A workaround for most cases is something like:
''' <summary>Lowercase value of Magic</summary>
Public Shared ReadOnly lcMagic As String = Magic.ToLower
But this do not provide intellisense of the actual value.
And not "secure" since it is possible to modify ReadOnly fields with reflection
So is there any way to declare 'const functions' at all, and if not, how do the framework really do it?
Edit: Checked the generated IL:
.field public static literal char Cr = char('\r')
Which means it is a special case for the compiler.