草庐IT

ACTION_CALL_PRIVILEGED

全部标签

c# - 为任何方法创建 Func 或 Action(在 C# 中使用反射)

我的应用程序根据设置动态加载dll来自数据库(文件、类和方法名称)。为了促进、加快和减少反射的使用,我想要一个缓存....遵循使用的想法:MethodInfo.Invoke没有任何表现形式(ReflectionPerformance-CreateDelegate(PropertiesC#))我想翻译对方法的任何调用。我想到了一些可以像这样工作的东西:publicstaticTCreate(Typetype,stringmethodName)//orpublicstaticTCreate(MethodInfoinfo)//touselikethis:varaction=Create>(t

c# - Action 过滤器 Action 参数

我有一个ActionFilterAttribute,我想通过它接受参数,但我不知道如何传递它们。所以我的Action过滤器看起来像这样;publicclassPreventAction:ActionFilterAttribute{publicoverridevoidOnActionExecuting(ActionExecutingContextfilterContext){filterContext.Result=newRedirectResult("Home/Index");}}然后我这样装饰我的Action;[PreventAction]publicActionResultIdea

c# - 多线程,Task.Run 错误 'The call is ambiguous between the following methods or properties'

当我尝试构建项目时,显示以下错误消息。Thecallisambiguousbetweenthefollowingmethodsorproperties:'System.Threading.Tasks.Task.Run(System.Action)'and'System.Threading.Tasks.Task.Run(System.Func)'我该如何解决这个问题?publicstaticclassMaintananceManager{privatestaticThreadSafeSocialMediaListPostList=newThreadSafeSocialMediaList(

c# - 在 Controller MVC 中自动生成 Action

我正在尝试更有效地使用VS,并且一直在寻找一种自动生成方法的方法。例如,我知道如果您键入foreach然后按TAB两次它会生成框架代码,所以如果我有这样的方法:[HttpPost]publicActionResultCloseTicket(){//dostuff}有没有一种生成“骨架代码”的方法,这样我就不必手动输入它了。我调查了methodstubs但它们似乎不适用于此。 最佳答案 VisualStudio中有内置的代码片段可以帮助解决这个问题:mvcaction4插入:publicActionResultAction(){ret

c# - 如何解决 Exception :Call was rejected by callee. (Exception from HRESULT : 0x80010001 (RPC_E_CALL_REJECTED)) in C#?

我在控制台应用程序中编写了一个C#代码来打开两个excel并将数据从一个excel复制并粘贴到另一个excel。在目标excel的可见性为真之前,它工作正常。但是我需要在执行时隐藏excel。所以我将可见性更改为false。喜欢,_destExcelApp=newExcel.ApplicationClass();_destExcelApp.Visible=false;现在它显示了一个异常Callwasrejectedbycallee.(ExceptionfromHRESULT:0x80010001(RPC_E_CALL_REJECTED))如何解决这个问题?

c# - 为什么 Func<...> 和 Action 不统一?

我发现自己一直想传递一个有返回值且没有输入的Func来代替Action,例如FuncDoSomething=...;Task.Run(DoSomething);在哪里,我真的不关心DoSomething的返回值。但是,这些类型并不统一,我最终结束了调用Task.Run(()=>{DoSomething();});有没有办法在不包装的情况下使这些类型统一?另外,它们不统一是否有好的设计原因? 最佳答案 您希望以下陈述为真:IfIhaveaFunc,IshouldbeabletouseitwhereanActionisrequired.

c# - 委托(delegate)操作 : new Action or casting Action?

我发现了两种不同的方法来使用Action初始化Delegate:创建一个新的Action或转换为Action。Delegatefoo=newAction(()=>DoNothing(param));Delegatebar=(Action)(()=>DoNothing(param));这两种语法有区别吗?哪个更好,为什么?此示例中使用了委托(delegate),因为语法对于使用lambda表达式调用BeginInvoke或Invoke等方法很有用,并且将lambda表达式转换为操作很重要staticmain{Invoke((Action)(()=>DoNothing()));//OKIn

c# - 创建一个 Action<T> 到 "set"属性,当我为 "get"提供 LINQ 表达式时

我希望能够生成编译表达式来设置属性,给定为属性提供“get”方法的lambda表达式。这是我正在寻找的:publicActionCreateSetter(Expression>getter){//returnsacompiledactionusingthedetailsofthegetterexpressiontree,ornull//ifthewritepropertyisnotdefined.}我仍在努力理解各种类型的Expression类,因此,如果您能为我指明正确的方向,那就太好了。 最佳答案 以@Ani的回答为起点,您可以

c# - 如何在 ASP.NET CORE 中使用具有依赖注入(inject)的 Action 过滤器?

我在我的ASP.NETCORE应用程序中到处使用基于构造函数的依赖注入(inject),我还需要在我的操作过滤器中解析依赖关系:publicclassMyAttribute:ActionFilterAttribute{publicintLimit{get;set;}//somecustomparameterspassedfromActionprivateICustomServiceCustomService{get;}//thismustberesolvedpublicMyAttribute(){}publicoverrideasyncTaskOnActionExecutionAsyn

c# - 为什么 Asp.net MVC 不能区分具有不同参数的两个 Action ?

我正在尝试在我的Asp.netMVC应用程序中使用两种不同的帐户注册方法,一种供一般用户注册,另一种供使用特定注册token注册的用户使用。因此,我的AccountController中有以下方法签名:publicvirtualActionResultRegister(){...}publicvirtualActionResultRegister(GuidregistrationToken){...}但是,当我转到http://localhost/Account/Register时,我得到一个异常,即当前请求在这两个操作之间不明确。我的印象是,如果没有传入registrationTok