VB 2008程序集中的扩展方法不能用于C#项目?
作者:互联网
我在VB程序集中编写了一些字符串扩展方法,并从C#项目中对它们进行单元测试.但是,C#表示它看不到扩展方法,当其他VB项目引用VB程序集时它们没有问题. VB可装配和C#测试项目都针对.Net 3.5.
有没有解决的办法?
VB.Net扩展方法:
Imports System.Runtime.CompilerServices
Imports System.Text.RegularExpressions
Imports System.Linq
Namespace ExtensionMethods
Module StringExtensions
<Extension()> _
Public Function Remove( _
ByVal input As String, _
ByVal subStrings As String()) As String
...
End Function
<Extension()> _
Public Function Substrings( _
ByVal input As String, _
ByVal regexPattern As String, _
ByVal regexOptions As RegexOptions) As IEnumerable(Of String)
...
End Function
<Extension()> _
Public Function Substrings( _
ByVal input As String, _
ByVal regexPattern As String) As IEnumerable(Of String)
...
End Function
End Module
End Namespace
VB.Net用法:
Imports SomeNamespace.ExtensionMethods
...
someString = someString.Remove(subStringsToRemove)
C#用法(不起作用):
using SomeNamespace.ExtensionMethods; //No error, but ExtensionMethods is not in the intellisense
...
someString = someString.Remove(subStringsToRemove); //error, can't find matching overlaod
解决方法:
试图让模块“公开”?
更新:
无法解释为什么它与其他VB程序集一起使用.认为C#有自己的类访问修饰符或其他东西的愿景.
标签:c,net,vb-net,extension-methods 来源: https://codeday.me/bug/20190630/1338725.html