VB.NET:使用GetLocalResourceObject的页面的扩展方法
在我们的.aspx页面中,我们有很多这样的代码:VB.NET:使用GetLocalResourceObject的页面的扩展方法,vb.net,localization,extension-methods,Vb.net,Localization,Extension Methods,在我们的.aspx页面中,我们有很多这样的代码: <%= CType(GetLocalResourceObject("key"), String)) %> 我想添加一个可在.aspx视图中使用的扩展方法,该方法允许我执行以下操作: <%= GetLocalResourceString("key") %> 但是,代码不起作用: Imports System.Runtime.CompilerServices Imports System.Web.UI Modul
<%= CType(GetLocalResourceObject("key"), String)) %>
我想添加一个可在.aspx视图中使用的扩展方法,该方法允许我执行以下操作:
<%= GetLocalResourceString("key") %>
但是,代码不起作用:
Imports System.Runtime.CompilerServices
Imports System.Web.UI
Module Extensions
<Extension()>
Public Function GetLocalResourceString(ByVal control as TemplateControl,
ByVal resourceKey as String) as String
Return CType(control.GetLocalResourceObject(resourceKey)), String)
End Sub
End Module
导入System.Runtime.CompilerServices
导入System.Web.UI
模块扩展
公共函数GetLocalResourceString(ByVal控件作为TemplateControl,
ByVal resourceKey(作为字符串)作为字符串
返回CType(control.GetLocalResourceObject(resourceKey)),字符串)
端接头
端模块
根据Intellisense,问题在于GetLocalResourceObject不作为System.Web.UI.TemplateControl对象的方法存在
然而,当我看到MSDN时,它就在那里
我做错了什么?扩展方法是否应位于其他对象上?我也尝试过其他方法,但出现了相同的Intellisense/build错误。GetLocalResourceObject受到保护,因此只能从页面内部调用它 我发布了一个类似的问题,看看是否有人知道如何在页面外打电话 我尝试创建一个继承Page对象的类,然后在内部公开一个名为GetLocalResourceObject的方法。我无法让它工作,因为当你通过我/这个时,你没有引用页面对象 以下是我的类似问题: