本文整理汇总了C#中System.Web.Mvc.ControllerBase.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ControllerBase.GetType方法的具体用法?C# ControllerBase.GetType怎么用?C# ControllerBase.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.ControllerBase
的用法示例。
在下文中一共展示了ControllerBase.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DetailActionParamsMapper
/// <summary>
/// Initializes a new instance of the <see cref="DetailActionParamsMapper"/> class.
/// </summary>
/// <param name="controller">The controller.</param>
/// <param name="itemType">Type of the item that is expected.</param>
/// <param name="providerNameResolver">A function that returns provider name for the content. If null then default provider is used.</param>
/// <param name="actionName">Name of the action.</param>
/// <exception cref="System.ArgumentException">When the given controller does not contain a method corresponding to the action name.</exception>
public DetailActionParamsMapper(ControllerBase controller, Type itemType, Func<string> providerNameResolver, string actionName)
: base(controller)
{
if (itemType == null)
throw new ArgumentNullException("itemType");
this.actionName = actionName;
this.providerNameResolver = providerNameResolver;
this.ActionMethod = new ReflectedControllerDescriptor(controller.GetType()).FindAction(controller.ControllerContext, actionName);
if (this.ActionMethod == null)
throw new ArgumentException("The controller {0} does not have action '{1}'.".Arrange(controller.GetType().Name, actionName));
this.ItemType = itemType;
}
示例2: GetActionDescriptor
private static ActionDescriptor GetActionDescriptor(ControllerBase controller, RouteData routeData)
{
var controllerDescriptor = new ReflectedControllerDescriptor(controller.GetType());
var actionName = routeData.GetRequiredString("action");
var actionDescriptor = controllerDescriptor.FindAction(controller.ControllerContext, actionName);
return actionDescriptor;
}
示例3: Resource
/// <summary>
/// Get the label with the specified key from the resource files.
/// </summary>
/// <param name="controller">Controller that requests the resource.</param>
/// <param name="key">The key.</param>
/// <param name="fallbackToKey">If true then if a resource is not found with the specified key the key is returned.</param>
private static string Resource(ControllerBase controller, RouteData routeData, string key, bool fallbackToKey)
{
var resClass = LocalizationHelpers.FindResourceStringClassType(controller.GetType());
var widgetName = routeData != null ? routeData.Values["widgetName"] as string : null;
if (!string.IsNullOrEmpty(widgetName))
{
var widget = FrontendManager.ControllerFactory.ResolveControllerType(widgetName);
if (widget != null)
{
var widgetResClass = LocalizationHelpers.FindResourceStringClassType(widget);
string res;
if (widgetResClass != null && Res.TryGet(widgetResClass.Name, key, out res))
{
return res;
}
}
}
string result;
if (Res.TryGet(resClass.Name, key, out result))
{
return result;
}
if (fallbackToKey)
{
return key;
}
return "#ResourceNotFound: {0}, {1}#".Arrange(resClass.Name, key);
}
示例4: TaxonomyUrlParamsMapper
/// <summary>
/// Initializes a new instance of the <see cref="TaxonomyUrlParamsMapper" /> class.
/// </summary>
/// <param name="controller">The controller.</param>
/// <param name="taxonUrlEvaluator">The taxon URL evaluator.</param>
/// <param name="actionName">Name of the action.</param>
public TaxonomyUrlParamsMapper(ControllerBase controller, TaxonUrlMapper taxonUrlEvaluator, string actionName = TaxonomyUrlParamsMapper.DefaultActionName)
: base(controller)
{
this.actionName = actionName;
this.taxonUrlEvaluator = taxonUrlEvaluator;
this.actionMethod = controller.GetType().GetMethod(this.actionName, BindingFlags.Instance | BindingFlags.Public);
}
示例5: CreateControllerContext
public static ControllerContext CreateControllerContext (ControllerBase controller, Dictionary<string, string> formValues,
HttpCookieCollection requestCookies, IDictionary<string, string> routeData)
{
HttpContextBase httpContext = CreateHttpContext ();
if (formValues != null) {
foreach (string key in formValues.Keys)
httpContext.Request.Form.Add (key, formValues[key]);
}
if (requestCookies != null) {
foreach (string key in requestCookies.Keys)
httpContext.Request.Cookies.Add (requestCookies[key]);
}
RouteData route = new RouteData ();
route.Values.Add ("controller", controller.GetType ().Name);
if (routeData != null) {
foreach (var valuePair in routeData)
route.Values.Add (valuePair.Key, valuePair.Value);
}
return new ControllerContext (new RequestContext (httpContext, route), controller);
}
示例6: GetFormletResult
public object GetFormletResult(ControllerBase controller, string actionName, HttpRequestBase request)
{
var type = formletType ?? controller.GetType();
var methodName = formletMethodName ?? (actionName + "Formlet");
var method = type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
if (method == null)
throw new Exception(string.Format("Formlet method '{0}' not found in '{1}'", methodName, type));
var formlet = method.Invoke(controller, null);
return formlet.GetType().GetMethod("Run").Invoke(formlet, new[] { GetCollectionBySource(request) });
}
示例7: FindModelType
protected virtual Type FindModelType(ControllerBase controller, string actionName)
{
ControllerDescriptor controllerDescriptor = new ReflectedControllerDescriptor(controller.GetType());
var actionDescriptor = controllerDescriptor.FindAction(controller.ControllerContext, actionName);
var qry = from p in actionDescriptor.GetParameters()
let paramType = p.ParameterType
where typeof(Csla.Core.IBusinessObject).IsAssignableFrom(paramType)
select paramType;
return qry.SingleOrDefault();
}
示例8: CustomActionParamsMapper
/// <summary>
/// Initializes a new instance of the <see cref="CustomActionParamsMapper"/> class.
/// </summary>
/// <param name="controller">The controller.</param>
/// <param name="routeTemplateResolver">This function should return the route template that the mapper will use.</param>
/// <param name="actionName">Name of the action.</param>
/// <exception cref="System.ArgumentNullException">routeTemplateResolver</exception>
public CustomActionParamsMapper(ControllerBase controller, Func<string> routeTemplateResolver, string actionName = CustomActionParamsMapper.DefaultActionName)
: base(controller)
{
if (routeTemplateResolver == null)
throw new ArgumentNullException("routeTemplateResolver");
this.actionName = actionName;
this.actionMethod = controller.GetType().GetMethod(this.actionName, BindingFlags.Instance | BindingFlags.Public);
this.routeTemplateResolver = routeTemplateResolver;
}
示例9: IsIlaroAdminController
protected virtual bool IsIlaroAdminController(ControllerBase controller)
{
var currentType = controller.GetType();
return currentType == typeof (EntitiesController) ||
currentType == typeof (EntityController) ||
currentType == typeof (AccountController) ||
currentType == typeof (GroupController) ||
currentType == typeof (ResourceController) ||
currentType == typeof (SharedController);
}
示例10: GetActionMethod
static MethodInfo GetActionMethod(HttpContextBase context, RouteData routeData, ControllerBase controller)
{
var actionName = routeData.Values["action"] as string;
if (actionName == null)
return null;
var controllerContext = new ControllerContext(context, routeData, controller);
var controllerDescriptor = new ReflectedControllerDescriptor(controller.GetType());
var actionDescriptor = controllerDescriptor.FindAction(controllerContext, actionName) as ReflectedActionDescriptor;
return actionDescriptor?.MethodInfo;
}
示例11: GetAuthorizeAttributes
/// <summary>
/// Avoids risking things like AmbiguousMatchException, by accessing the controller and action descriptors.
/// </summary>
internal IEnumerable<AuthorizeAttribute> GetAuthorizeAttributes(ControllerBase controller, string actionName)
{
ControllerDescriptor controllerDescriptor = new ReflectedControllerDescriptor(controller.GetType());
ActionDescriptor actionDescriptor = controllerDescriptor.FindAction(controller.ControllerContext, actionName);
if (actionDescriptor == null)
{
// if we can't find a matching action descriptor, we just issue a warning log and trim the action from the site map.
log.Warn(Exceptions.MiniAclModule_ActionDescriptorNotFound.FormatWith(controllerDescriptor.ControllerName, actionName));
return new AuthorizeAttribute[] { new UnauthorizedAttribute() };
}
IEnumerable<AuthorizeAttribute> controllerAttributes = controllerDescriptor.GetAttributes<AuthorizeAttribute>();
IEnumerable<AuthorizeAttribute> actionAttributes = actionDescriptor.GetAttributes<AuthorizeAttribute>();
return controllerAttributes.Concat(actionAttributes);
}
示例12: GetProviderNames
private IEnumerable<string> GetProviderNames(ControllerBase controller, Type contentType)
{
var providerNameProperty = controller.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).FirstOrDefault(p => p.Name == "ProviderName" && p.PropertyType == typeof(string));
if (providerNameProperty != null)
{
return new string[1] { providerNameProperty.GetValue(controller, null) as string };
}
else
{
var mappedManager = ManagerBase.GetMappedManager(contentType);
if (mappedManager != null)
{
return mappedManager.Providers.Select(p => p.Name);
}
else
{
return new string[0];
}
}
}
示例13: DisplayModelStateErrors
private void DisplayModelStateErrors(ControllerBase currentController)
{
// Show the ModelState errors in the standard Cuyahoga errorbox.
if (!currentController.ViewData.ModelState.IsValid)
{
string generalMessage = this._localizer.GetString("ModelValidationErrorMessage");
TagBuilder errorList = new TagBuilder("ul");
StringBuilder errorSummary = new StringBuilder();
foreach (KeyValuePair<string, ModelState> modelStateKvp in currentController.ViewData.ModelState)
{
foreach (ModelError modelError in modelStateKvp.Value.Errors)
{
TagBuilder listItem = new TagBuilder("li");
string baseName = String.Format("{0}.globalresources"
, currentController.GetType().Namespace.Replace(".Controllers", String.Empty).ToLowerInvariant());
listItem.SetInnerText(this._localizer.GetString(modelError.ErrorMessage, baseName));
errorSummary.AppendLine(listItem.ToString(TagRenderMode.Normal));
}
}
errorList.InnerHtml = errorSummary.ToString();
this._messageViewData.AddErrorMessage(generalMessage + errorList.ToString(TagRenderMode.Normal));
}
this._messageViewData.FlashMessageAdded -= new EventHandler(MessageViewData_FlashMessageAdded);
}
示例14: GetPermisoAction
private TipoPermiso GetPermisoAction(string actionName, ControllerBase controller, string verb)
{
var methodInfo = controller.GetType().GetMethods().FirstOrDefault(p =>
p.Name == actionName &&
p.CustomAttributes.Any(
q =>
verb == HttpVerbs.Get.ToString().ToUpperInvariant()
? q.AttributeType == typeof (HttpGetAction)
: q.AttributeType == typeof (HttpPostAction)));
if (methodInfo == null)
throw new Exception("No se ha asignado los atributos correspondientes en el controlador....");
var attributePermiso = methodInfo.GetCustomAttributes(typeof (IPermiso), true).FirstOrDefault() as IPermiso;
return attributePermiso.GetPermiso();
}
示例15: IsAllowedAnonymousAccess
public static bool IsAllowedAnonymousAccess(ControllerBase controller)
{
bool isAllowedAnonymous = controller.GetType().IsDefined(typeof(Cruder.Web.Auth.Attributes.AllowAnonymousAccess), true);
return isAllowedAnonymous;
}