Vb.net 是否有任何设计模式的匿名方法替代方法

本文关键字:方法 设计模式 net 是否 任何 Vb | 更新日期: 2023-09-27 18:31:46

使用

C# 匿名委托,我们可以避免声明额外的方法,我知道它们 VB.NET 不可用,但是是否有一种设计模式可供我使用,以便我可以避免每次都编写额外的方法?我需要它用于SPSecurity.RunWithElevatedPrivileges,它将在我们的代码中多次使用。

例如

SPSecurity.RunWithElevatedPrivileges(
                    delegate()
                    {
                        //some code here. 
                    }
                );

我想在 VB.NET 做这样的事情:

using RunWithElevatedPrivil() 
'some code here. 
end using 

Vb.net 是否有任何设计模式的匿名方法替代方法

检查此链接,它可能会有所帮助:

http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/4854962a-0d4e-40e4-909a-581bb7a5ab03

在 vb.net 中,您可以定义一个无参数的子,该子执行您的代码 希望以更高的权限执行并将其声明为 CodeToRunElevated:

您必须定义模块级变量以供其使用。

Dim secureCode as new SPSecurity.CodeToRunElevated(AddressOf Me.SPCode) SPSecurity.RunWithElevatedPrivileges(secureCode)