简体   繁体   English

VB.Net页面中具有ASP.Net导入指令的别名通用类型

[英]Alias Generic Type With ASP.Net Import Directive in VB.Net Page

I can't seem to import a generic type on an ASP.Net page set to a language of "vb": 我似乎无法在设置为“ vb”语言的ASP.Net页面上导入通用类型:

<%@ Page Language="vb" %>
<%-- This works fine. --%>
<%@ Import Namespace="MyString=System.String" %>
<%-- This gives an error. --%>
<%@ Import Namespace="MyList=System.Collections.Generic.List(Of System.String)" %>
<%-- Error: "The 'namespace' attribute cannot contain spaces." --%>

Note that I'm NOT interested in these alternatives (for boring reasons you don't care about): 请注意,我对这些替代方案不感兴趣(由于您不关心的无聊原因):

  • Alter the web.config. 更改web.config。
  • Alter the code-behind. 更改后面的代码。
  • Use the code-behind instead of the page. 使用后台代码代替页面。
  • Using C# instead of VB.Net. 使用C#代替VB.Net。
  • Googling (the MSDN page makes no mention of generic types). 谷歌搜索(MSDN页面未提及泛型类型)。
  • Modifying the app.config. 修改app.config。
  • Adding the namespace to the "imported namespaces" via the "References" tab in the project settings. 通过项目设置中的“引用”选项卡将名称空间添加到“导入的名称空间”中。
  • Workarounds (I already have workarounds, but I want to see if this can be done properly) 解决方法(我已经有了解决方法,但是我想看看是否可以正确完成此操作)

Is it possible to alias a generic type on a VB.Net ASP.Net page, or is this an oversight by Microsoft? 是否可以在VB.Net ASP.Net页面上为通用类型添加别名,或者这是Microsoft的疏忽?

Yeah, bad news: 是的,坏消息:

  1. You can't alias a generic type anywhere in .NET (may have changed recently, don't think so). 您不能在.NET中的任何地方使用通用类型的别名 (可能最近有所更改,请不要这样认为)。
  2. You can't import a namespace with a space in it, in ASP.NET. 在ASP.NET中,不能导入其中带有空格的名称空间。 It's the parser for the ASPX that's the issue. 问题是ASPX的解析器。 Yep, Microsoft oversight. 是的,微软的监督。 Since C# would be List<System.String> , it would not throw the error. 由于C#将是List<System.String> ,因此不会引发错误。 They left out VB again. 他们再次省略了VB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM