[英]Extension Methods in VB 2008 assembly cannot be used in a C# project?
I wrote some string extension methods in a VB assembly and am unit testing them from a C# project.我在 VB 程序集中编写了一些字符串扩展方法,并从 C# 项目对它们进行了单元测试。 However, C# acts like it cannot see the the extension methods, when other VB projects reference the VB assembly they have no problem.但是,C# 就像看不到扩展方法一样,当其他 VB 项目引用 VB 程序集时,它们没有问题。 Both the VB assemebly and the C# test project are targeting.Net 3.5. VB 程序集和 C# 测试项目都针对.Net 3.5。
Is there a way around this?有没有解决的办法?
VB.Net extension methods: 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 usage: VB.Net 用法:
Imports SomeNamespace.ExtensionMethods
...
someString = someString.Remove(subStringsToRemove)
C# usage (doesn't work): C# 用法(不起作用):
using SomeNamespace.ExtensionMethods; //No error, but ExtensionMethods is not in the intellisense
...
someString = someString.Remove(subStringsToRemove); //error, can't find matching overlaod
Tried to make the module 'Public'?试图使模块“公共”?
Update:更新:
Can't explain why it worked with other VB assemblies.无法解释为什么它与其他 VB 程序集一起使用。 Think that C# has its own vision of class access modifiers or something.认为 C# 对 class 访问修饰符或其他东西有自己的看法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.