简体   繁体   English

VB 2008 程序集中的扩展方法不能在 C# 项目中使用?

[英]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.

相关问题 如何在C#项目中使用VB.Net扩展方法 - How can I use VB.Net extension methods in a C# project 将 VB.NET 2005 项目转换为 C# 2008 项目 - Convert VB.NET 2005 project to C# 2008 Project C# - 无法调用 HttpConfiguration 扩展方法 - C# - Cannot call a HttpConfiguration Extension Methods 如何在VB代码中调用C#扩展方法 - How can I call C# extension methods in VB code C#扩展方法 - C# Extension Methods 使用VBCodeProvider()。CompileAssemblyFromSource在C#中构建VB程序集,但无法访问VB代码中的函数 - Building VB assembly in C# using VBCodeProvider().CompileAssemblyFromSource but cannot access functions inside VB code 引用 VB.NET 项目的 C# 项目:找不到程序集“Microsoft.VisualBasic,版本 10.0.0.0” - C# project referring to VB.NET project: Could not find assembly 'Microsoft.VisualBasic, Version 10.0.0.0' 在Visual C#2008中引用基础设施程序集 - Referencing Infragistics Assembly in Visual C# 2008 如何在Visual Studio 2008中将程序集清单添加到C#.NET类库项目? - How to add assembly manifest to a C# .NET class library project in Visual Studio 2008? 我可以将 C# 扩展方法的可见性限制为同一程序集中的类吗? - Can I restrict the visibility of C# extension methods to classes in the same assembly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM