vblang icon indicating copy to clipboard operation
vblang copied to clipboard

[Proposal]: Mark methods of Microsoft.VisualBasic.Information module with [Extension]

Open VBAndCs opened this issue 5 years ago • 3 comments

Based on #546, #547 I suggest to:

  1. Mark methods of Microsoft.VisualBasic.Information module with the ExtensionAttribute.
  2. Make the compiler look at this special module first to resolve extension methods for objects if they are not members of the type itself, ignoring Option Strict On and any current limitations due to late binding. After all this is only one intrinsic module containing object-related jobs. SO, we can write:
   If x.IsDbNull Then
  1. Add some more useful functions to the module to shorten object checks syntax, such as IsSomething or HasValueor alike as proposed in #546.
   If x.HasValue Then

VBAndCs avatar Aug 06 '20 11:08 VBAndCs

@VBAndCs Maybe also raise the issue on the runtime repo.

https://github.com/dotnet/runtime/issues

AdamSpeight2008 avatar Aug 06 '20 12:08 AdamSpeight2008

It is a VB.NET issue, since it needs a special treatment of the compiler. There is also the issue when the object is Nothing. The workaround is to use the ? operator: If x?.IsDbNull I think we should not need the ? since this is an extension method, but I don't know how the compiler acts in this case in runtime.

VBAndCs avatar Aug 06 '20 14:08 VBAndCs

It is a VB.NET issue, since it needs a special treatment of the compiler. There is also the issue when the object is Nothing. The workaround is to use the ? operator: If x?.IsDbNull I think we should not need the ? since this is an extension method, but I don't know how the compiler acts in this case in runtime.

hmmm. I like how you're thinking here, but....

dim haveValue = x.IsDbNull

vs

dim haveValue = x?.IsDbNull

what's the correct response in each case if x is nothing ?

pricerc avatar Aug 06 '20 20:08 pricerc