本文整理汇总了C#中IController.GetAllMethods方法的典型用法代码示例。如果您正苦于以下问题:C# IController.GetAllMethods方法的具体用法?C# IController.GetAllMethods怎么用?C# IController.GetAllMethods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IController
的用法示例。
在下文中一共展示了IController.GetAllMethods方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupViewPage
private static void SetupViewPage(IController controller, object viewPage, object viewData)
{
// Set the page's ViewData to the ViewData of the controller
foreach (var item in controller.ViewData) {
((Dictionary<string, object>)viewData).Add(item.Key, item.Value);
}
viewData.SetPropertyValue("Model", controller.ViewData.Model);
// Sets the page's FSG Identification if the FSGAuthorizeAttribute is used.
// Controller setting rulez all.
var att = controller.GetType().GetCustomAttributes(typeof(FSGAuthorizeAttribute), false).FirstOrDefault();
if (att != null) {
((FSGAuthorizeAttribute)att).setPageIdentification((FrameworkPage)viewPage);
}
else {
var method = controller.GetAllMethods().Where(m => m.Name.ToLower() == controller.ViewData["action"].ToString().ToLower()).FirstOrDefault();
att = method.GetCustomAttributes(typeof(FSGAuthorizeAttribute), false).FirstOrDefault();
if (att != null) {
((FSGAuthorizeAttribute)att).setPageIdentification((FrameworkPage)viewPage);
}
}
}
示例2: GetControllerMethodToCallFromRequestType
private static MethodInfo GetControllerMethodToCallFromRequestType(RequestContext requestContext, IController controller, string actionName)
{
var methods = controller.GetAllMethods().Where(m =>
m.Name.ToLower() == actionName.ToLower() &&
m.IsPublic &&
m.ReturnType.BaseType == typeof(ActionResult));
foreach (var method in methods) {
var atts = method.GetCustomAttributes(false);
foreach (var a in atts) {
if (a is HttpGet && requestContext.HttpContext.Request.HttpMethod == "GET")
return method;
else if (a is HttpPost && requestContext.HttpContext.Request.HttpMethod == "POST")
return method;
else if (a is HttpDelete && requestContext.HttpContext.Request.HttpMethod == "DELETE")
return method;
}
}
if (methods.FirstOrDefault() == null)
throw new Exception(String.Format("Action: {0} is not defined in the controller.", actionName));
return methods.First();
}