Adding a keyword to VB.net? ("Exists" versus "IsNot Nothing")

IsNot Nothing very common, but it's double negative = o

I would like to use Exists . Is there a way to add a keyword to my VB vocab?

Currently, I have written an extension that adds _Exists() as a property for each object. I often use this, but I would prefer the actual keyword.

 <HideModuleName()> Public Module CustomExtensions ''' <summary> ''' Returns <c>True</c> if [object] is not <c>Nothing</c>; otherwise <c>False</c>. ''' </summary> <System.Runtime.CompilerServices.Extension()> Public Function _Exists(obj As Object) As Boolean Return obj IsNot Nothing End Function End Module 

I use only Visual Studio 2010, so if I could trick VS into converting my special phraseology into standard syntax, this would work for me.

Thanks!

+6
source share
1 answer

This answer is not very useful, but it goes here: currently you cannot do this .

Future versions of VS (especially when they release internal compiler services and make them extensible) may allow this, although I really doubt that they will allow adding new keywords, as this is not in the interests of the compiler provider who wants to provide an ecosystem of compatible code.

+5
source

Source: https://habr.com/ru/post/895610/


All Articles