扩展和 CodeDomProvider

发布于 2024-11-26 14:49:25 字数 1690 浏览 1 评论 0原文

我在使用 CodeDomProvider 时遇到问题。当我编译VB代码时,没有错误。但是,如果此代码具有扩展名(例如:string().contains()char().countchar().AsEnumerable等)在我调用这些函数时,它返回一个对于所有这些扩展都相同的异常:

“公共成员‘计数’在类型‘Char()’未找到”

‘公共成员’包含’在类型'String()' not found'


Dim refs() As String = {"mscorlib.dll", "System.dll", "Microsoft.VisualBasic.dll","system.xml.dll", "system.core.dll", "system.data.dll"}

oCParams.ReferencedAssemblies.AddRange(refs)

这些是编译引用的程序集,并且也配置为在 Framework 4.0 中运行。


    Dim Param As New Dictionary(Of String, String)

    Param.Add("CompilerVersion", "v4.0")

    Dim oCodeProvider = CodeDomProvider.CreateProvider("VisualBasic", Param)

该代码位于字符串内:

Imports System
Imports System.Xml
Imports System.Data
Imports System.Collections
Imports System.Linq.Expressions
Imports System.Linq
Imports System.String
Imports System.Linq.Enumerable
Imports System.Collections.Generic
Imports System.Runtime.CompilerServices
Imports System.Runtime.CompilerServices.ExtensionAttribute

Namespace Teste
Class Classe
Public Shared Function ProcessarLink(ByVal URL As System.Uri) As Boolean
Dim QueryString = URL.Query.Remove(0, 1).Split("&"c).tolist

If QueryString.Contains("xxx") Then
...
End If

End Function 
Public Shared Function Personalizar(ByRef Vetor() As Char) As System.Collections.Generic.Dictionary(Of String,Object) 
...
Dim Total As Integer = Vetor.Count
...
End Function 
End Class 
End Namespace

在我使用它来编译我的程序集之后。

代码编译时没有错误,但是当我调用函数“ProcessarLink”时,它会返回“Contains”中的异常,或者当我调用函数“Personalizar”时,错误会显示为“Count”。其他扩展也会发生这种情况,例如 AsEnumerable 等。

问题是什么?

I am having problems with CodeDomProvider. When I compile a code VB, there is not an error. But, if this code has extensions (ex: string().contains(), char().count, char().AsEnumerable, etc.) at the moment that I call these functions, it's returns an exception equal for all these extensions:

'Public Member 'Count' at type 'Char()' not found'

'Public Member 'Contains' at type 'String()' not found'


Dim refs() As String = {"mscorlib.dll", "System.dll", "Microsoft.VisualBasic.dll","system.xml.dll", "system.core.dll", "system.data.dll"}

oCParams.ReferencedAssemblies.AddRange(refs)

These are the Assembly that is referenced to the compile, and this is also configurated for run in Framework 4.0.


    Dim Param As New Dictionary(Of String, String)

    Param.Add("CompilerVersion", "v4.0")

    Dim oCodeProvider = CodeDomProvider.CreateProvider("VisualBasic", Param)

This code is inside a string:

Imports System
Imports System.Xml
Imports System.Data
Imports System.Collections
Imports System.Linq.Expressions
Imports System.Linq
Imports System.String
Imports System.Linq.Enumerable
Imports System.Collections.Generic
Imports System.Runtime.CompilerServices
Imports System.Runtime.CompilerServices.ExtensionAttribute

Namespace Teste
Class Classe
Public Shared Function ProcessarLink(ByVal URL As System.Uri) As Boolean
Dim QueryString = URL.Query.Remove(0, 1).Split("&"c).tolist

If QueryString.Contains("xxx") Then
...
End If

End Function 
Public Shared Function Personalizar(ByRef Vetor() As Char) As System.Collections.Generic.Dictionary(Of String,Object) 
...
Dim Total As Integer = Vetor.Count
...
End Function 
End Class 
End Namespace

After I use it for compile my Assembly.

The code compiles without errors, but when I call the function 'ProcessarLink', it returns me the exception in 'Contains', or when I call the function 'Personalizar' the errors appears with the 'Count'. This happens with the others extensions too, like AsEnumerable, etc.

What is the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尛丟丟 2024-12-03 14:49:25

听起来您的代码文件需要导入扩展方法 - 即它不包括:

Imports System.Linq

您这样做了吗?如果没有,您可以发布一个您看到错误的示例 vb 代码文件吗?

It sounds like your codefile needs to import the extension methods - i.e. it doesn't include:

Imports System.Linq

Have you done that? If not, can you post an example vb codefile where you are seeing the errors?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文