Solved: IntelliSense just doesn't show the Extension!
Lets say we got the following extension method in F#:
[<Extension>]
module Extension =
[<Extension>]
let Increment(value : System.Int32) = value + 1
In C# I can call it like this way:
x.Increment(); //Result x=1
But the equivalent VB code to this returns an error, it doesn't find the extension method for the type integer:
x.Increment() 'No method called "Increment()" for type Int32
While it's possible to call the method by the standard way:
Increment(x) 'Works
So where is the difference between handling VB and C# on calling F# code, why isn't the VB environment able to resolve the extension methods?
If you build a regular F# library project
namespace A
open System.Runtime.CompilerServices
[<Extension>]
module Extension =
[<Extension>]
let Increment(value : System.Int32) = value + 1
and then refer to this library from VB project
Imports A.Extension
Module Module1
Sub Main()
Console.WriteLine((1).Increment())
End Sub
End Module
then VB treats F# extension method as expected <Extension>Public Function Increment() As Integer
and works correctly, giving 2
as output.
A clean experiment does not indicate any VB-specific idiosyncrasy to F#-defined extension methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With