Adding a keyword to VB.net? ("Exists" vs "IsNot Nothing")
IsNot Nothing
is very common, but it's a double negative =o
I'd like to use Exists
instead. Is there someway I can add a keyword to my VB vocab?
For now, I wrote an extension that adds _Exists()
as a property to each object. I use this frequently, but I'd still prefer an actual keyword.
开发者_Go百科<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 Visual Studio 2010 exclusively, so if I could trick VS into converting my custom phraseology into the standard syntax, that'd work for me.
Thanks!
This answer isn’t very helpful but here goes: currently, you cannot do this.
Future versions of VS (particularly when they release their compiler service internals and make them extensible) could allow it – although I actually doubt that they will allow new keywords to be added, as this isn’t in the interest of a compiler vendor who wants to ensure an ecosystem of compatible code.
精彩评论