开发者

VB.NET Is there a way to create a pre-processor constant that behaves as a simple text substitution?

开发者 https://www.devze.com 2023-02-09 09:15 出处:网络
VB.NET 2010, .NET 4 Hello, I would like to do (something like) the following: \\#Const T = \"Byte()\" Public Class MyClass

VB.NET 2010, .NET 4

Hello,

I would like to do (something like) the following:

\#Const T = "Byte()"

Public Class MyClass
  Inherits SomeGenericClass(Of T)

  .. other code ..
End Class

And have it act the same as if I'd typed

Public Class MyClass
  Inherits SomeGenericClass(Of Byte())

  .. other code ..
End Class

It's not so much that i have to do it this way, I'm just curious if such a thing is possible.

Thanks in advance!

Br开发者_开发百科ian


No, this is not possible. The Visual Basic and C# designers decided not to allow a C-like preprocessor, because they felt it led to a lot of errors and confusion. It is very easy to write C macros that behave in unintended ways, and the VB and C# designers felt that safety for a broad range of developers took priority. Therefore defines in VB and C# are only 'defined' or 'undefined' rather than having values.

Eric Gunnerson discusses this from a C# perspective here, and I think the design reasoning for VB.NET was essentially the same.


You only have: #Const #If #Else #Endif But, you can use another program to generate the code.

0

精彩评论

暂无评论...
验证码 换一张
取 消