本文整理汇总了C#中System.Reflection.MethodInfo.IsDefined方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.IsDefined方法的具体用法?C# MethodInfo.IsDefined怎么用?C# MethodInfo.IsDefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.IsDefined方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterMethod
public static void RegisterMethod(MethodInfo method)
{
if (method == null)
throw new ArgumentNullException("method");
methods.Add(method);
foreach (RegistrarMethodHandler handler in methodhandlers)
{
handler(method);
}
if (method.IsDefined(typeof(RegistrarTypeHandlerAttribute),false))
{
RegistrarTypeHandler handler = (RegistrarTypeHandler)Delegate.CreateDelegate(typeof(RegistrarTypeHandler),method);
typehandlers.Add(handler);
foreach (Type type in types)
{
handler(type);
}
}
if (method.IsDefined(typeof(RegistrarMethodHandlerAttribute),false))
{
RegistrarMethodHandler handler = (RegistrarMethodHandler)Delegate.CreateDelegate(typeof(RegistrarMethodHandler),method);
methodhandlers.Add(handler);
foreach (MethodInfo method2 in methods)
{
handler(method2);
}
}
}
示例2: ShouldSaveAudit
/// <summary>
/// 应该保存审计
/// </summary>
/// <param name="methodInfo">方法信息</param>
/// <param name="configuration">审计配置</param>
/// <param name="abpSession">Abp会话</param>
/// <param name="defaultValue">默认值</param>
/// <returns></returns>
public static bool ShouldSaveAudit(MethodInfo methodInfo, IAuditingConfiguration configuration, IAbpSession abpSession, bool defaultValue = false)
{
//审计配置为null,或审计配置未启用,则返回false
if (configuration == null || !configuration.IsEnabled)
{
return false;
}
//如果未启用匿名用户,并且AbpSession为null或用户Id为空,返回false
if (!configuration.IsEnabledForAnonymousUsers && (abpSession == null || !abpSession.UserId.HasValue))
{
return false;
}
//如果方法信息为null
if (methodInfo == null)
{
return false;
}
//如果方法信息不为公共方法
if (!methodInfo.IsPublic)
{
return false;
}
//如果方法使用了AuditedAttribute审计自定义属性,则返回true
if (methodInfo.IsDefined(typeof(AuditedAttribute)))
{
return true;
}
//如果方法使用了DisableAuditingAttribute禁用审计自定义属性,则返回false
if (methodInfo.IsDefined(typeof(DisableAuditingAttribute)))
{
return false;
}
//获取声明该成员的类
var classType = methodInfo.DeclaringType;
if (classType != null)
{
if (classType.IsDefined(typeof(AuditedAttribute)))
{
return true;
}
if (classType.IsDefined(typeof(DisableAuditingAttribute)))
{
return false;
}
if (configuration.Selectors.Any(selector => selector.Predicate(classType)))
{
return true;
}
}
return defaultValue;
}
示例3: GetMemberAttributes
public static PhpMemberAttributes GetMemberAttributes(MethodInfo/*!*/ info)
{
PhpMemberAttributes value = PhpMemberAttributes.None;
if (info.IsPublic) value |= PhpMemberAttributes.Public;
else if (info.IsFamily) value |= PhpMemberAttributes.Protected;
else if (info.IsPrivate) value |= PhpMemberAttributes.Private;
if (info.IsStatic)
{
value |= (PhpMemberAttributes.Static | PhpMemberAttributes.AppStatic);
}
// "finalness" and "abstractness" is stored as attributes, if the method is static, not in MethodInfo
// (static+abstract, static+final are not allowed in CLR)
//Debug.Assert(!(info.IsStatic && (info.IsFinal || info.IsAbstract)), "User static method cannot have CLR final or abstract modifier.");
if (info.IsAbstract || info.IsDefined(typeof(PhpAbstractAttribute), false))
value |= PhpMemberAttributes.Abstract;
if (info.IsFinal || info.IsDefined(typeof(PhpFinalAttribute), false))
value |= PhpMemberAttributes.Final;
return value;
}
示例4: ShouldSaveAudit
/// <summary>
/// <see cref="MethodInfo"/> 标记 <see cref="AuditedAttribute"/> 或者 <see cref="IAuditingConfiguration"/> 已经 将进行拦截,开启审计功能
/// </summary>
/// <param name="methodInfo"></param>
/// <param name="configuration"></param>
/// <param name="owSession"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static bool ShouldSaveAudit(MethodInfo methodInfo, IAuditingConfiguration configuration, IOwSession owSession, bool defaultValue = false)
{
if (configuration == null || !configuration.IsEnabled)
{
return false;
}
if (!configuration.IsEnabledForAnonymousUsers && (owSession == null || !owSession.UserId.HasValue))
{
return false;
}
if (methodInfo == null)
{
return false;
}
if (!methodInfo.IsPublic)
{
return false;
}
if (methodInfo.IsDefined(typeof(AuditedAttribute)))
{
return true;
}
if (methodInfo.IsDefined(typeof(DisableAuditingAttribute)))
{
return false;
}
//获取父类信息,判断是否开启审计
var classType = methodInfo.DeclaringType;
if (classType != null)
{
if (classType.IsDefined(typeof(AuditedAttribute)))
{
return true;
}
if (classType.IsDefined(typeof(DisableAuditingAttribute)))
{
return false;
}
if (configuration.Selectors.Any(selector => selector.Predicate(classType)))
{
return true;
}
}
return defaultValue;
}
示例5: ShouldSaveAudit
public bool ShouldSaveAudit(MethodInfo methodInfo, bool defaultValue = false)
{
if (!_configuration.IsEnabled)
{
return false;
}
if (!_configuration.IsEnabledForAnonymousUsers && (AbpSession?.UserId == null))
{
return false;
}
if (methodInfo == null)
{
return false;
}
if (!methodInfo.IsPublic)
{
return false;
}
if (methodInfo.IsDefined(typeof(AuditedAttribute), true))
{
return true;
}
if (methodInfo.IsDefined(typeof(DisableAuditingAttribute), true))
{
return false;
}
var classType = methodInfo.DeclaringType;
if (classType != null)
{
if (classType.IsDefined(typeof(AuditedAttribute), true))
{
return true;
}
if (classType.IsDefined(typeof(DisableAuditingAttribute), true))
{
return false;
}
if (_configuration.Selectors.Any(selector => selector.Predicate(classType)))
{
return true;
}
}
return defaultValue;
}
示例6: ActionMethod
public ActionMethod(MethodInfo methodInfo)
{
_methodInfo = methodInfo;
_filterAttributes = (ActionFilterAttribute[]) methodInfo.GetCustomAttributes(typeof(ActionFilterAttribute), false);
OrderedAttribute.Sort(_filterAttributes);
if (_methodInfo.IsDefined(typeof(LayoutAttribute), false))
_defaultLayoutName = ((LayoutAttribute)_methodInfo.GetCustomAttributes(typeof(LayoutAttribute), false)[0]).LayoutName ?? "";
if (_methodInfo.IsDefined(typeof(ViewAttribute), false))
_defaultViewName = ((ViewAttribute)_methodInfo.GetCustomAttributes(typeof(ViewAttribute), false)[0]).ViewName ?? "";
}
示例7: ParameterizedMethodSuite
/// <summary>
/// Construct from a MethodInfo
/// </summary>
/// <param name="method"></param>
public ParameterizedMethodSuite(MethodInfo method)
: base(method.ReflectedType.FullName, method.Name)
{
Method = method;
_isTheory = method.IsDefined(typeof(TheoryAttribute), true);
this.MaintainTestOrder = true;
}
示例8: CreateGet
public LateBoundMethod CreateGet(MethodInfo method)
{
ParameterExpression instanceParameter = Expression.Parameter(typeof(object), "target");
ParameterExpression argumentsParameter = Expression.Parameter(typeof(object[]), "arguments");
MethodCallExpression call;
if (!method.IsDefined(typeof(ExtensionAttribute), false))
{
// instance member method
call = Expression.Call(
Expression.Convert(instanceParameter, method.DeclaringType),
method,
CreateParameterExpressions(method, instanceParameter, argumentsParameter));
}
else
{
// static extension method
call = Expression.Call(
method,
CreateParameterExpressions(method, instanceParameter, argumentsParameter));
}
Expression<LateBoundMethod> lambda = Expression.Lambda<LateBoundMethod>(
Expression.Convert(call, typeof(object)),
instanceParameter,
argumentsParameter);
return lambda.Compile();
}
示例9: ShouldValidate
public static bool ShouldValidate(
this IAbpAntiForgeryManager manager,
IAbpAntiForgeryWebConfiguration antiForgeryWebConfiguration,
MethodInfo methodInfo,
HttpVerb httpVerb,
bool defaultValue)
{
if (!antiForgeryWebConfiguration.IsEnabled)
{
return false;
}
if (methodInfo.IsDefined(typeof(ValidateAbpAntiForgeryTokenAttribute), true))
{
return true;
}
if (ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault<DisableAbpAntiForgeryTokenValidationAttribute>(methodInfo) != null)
{
return false;
}
if (antiForgeryWebConfiguration.IgnoredHttpVerbs.Contains(httpVerb))
{
return false;
}
if (methodInfo.DeclaringType?.IsDefined(typeof(ValidateAbpAntiForgeryTokenAttribute), true) ?? false)
{
return true;
}
return defaultValue;
}
示例10: Matches
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// </summary>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">The target <see cref="System.Type"/> (may be <see langword="null"/>,
/// in which case the candidate <see cref="System.Type"/> must be taken
/// to be the <paramref name="method"/>'s declaring class).</param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
/// <remarks>
/// <p>
/// Must be implemented by a derived class in order to specify matching
/// rules.
/// </p>
/// </remarks>
public override bool Matches(MethodInfo method, Type targetType)
{
if (method.IsDefined(attributeType, true))
{
// Checks whether the attribute is defined on the method or a super definition of the method
// but does not check attributes on implemented interfaces.
return true;
}
else
{
Type[] parameterTypes = ReflectionUtils.GetParameterTypes(method);
// Also check whether the attribute is defined on a method implemented from an interface.
// First find all interfaces for the type that contains the method.
// Next, check each interface for the presence of the attribute on the corresponding
// method from the interface.
foreach (Type interfaceType in method.DeclaringType.GetInterfaces())
{
MethodInfo intfMethod = interfaceType.GetMethod(method.Name, parameterTypes);
if (intfMethod != null && intfMethod.IsDefined(attributeType, true))
{
return true;
}
}
return false;
}
}
示例11: AllowsUnauthorized
private Boolean AllowsUnauthorized(Type authorizedControllerType, MethodInfo method)
{
if (method.IsDefined(typeof(AuthorizeAttribute), false)) return false;
if (method.IsDefined(typeof(AllowAnonymousAttribute), false)) return true;
if (method.IsDefined(typeof(AllowUnauthorizedAttribute), false)) return true;
while (authorizedControllerType != typeof(Controller))
{
if (authorizedControllerType.IsDefined(typeof(AuthorizeAttribute), false)) return false;
if (authorizedControllerType.IsDefined(typeof(AllowAnonymousAttribute), false)) return true;
if (authorizedControllerType.IsDefined(typeof(AllowUnauthorizedAttribute), false)) return true;
authorizedControllerType = authorizedControllerType.BaseType;
}
return true;
}
示例12: IsActionMethod
protected virtual bool IsActionMethod(MethodInfo method)
{
Precondition.Require(method, () => Error.ArgumentNull("method"));
if (method.IsDefined(typeof(IgnoreActionAttribute), false))
return false;
return (!method.IsAbstract && !method.IsSpecialName && !method.ContainsGenericParameters &&
typeof(Controller).IsAssignableFrom(method.GetBaseDefinition().DeclaringType));
}
示例13: AcceptMethod
/// <inheritdoc/>
public bool AcceptMethod(MethodInfo methodInfo)
{
if (methodInfo.IsDefined(typeof (NonInterceptedAttribute), false))
return false;
if (methodInfo.DeclaringType != typeof (object))
return true;
return !String.Equals(methodInfo.Name, DestructorMethodName);
}
示例14: GetMethodType
// These methods might be more commonly overridden for a given C++ ABI:
public virtual MethodType GetMethodType (CppTypeInfo typeInfo, MethodInfo imethod)
{
if (IsInline (imethod) && !IsVirtual (imethod) && typeInfo.Library.InlineMethodPolicy == InlineMethods.NotPresent)
return MethodType.NotImplemented;
else if (imethod.IsDefined (typeof (ConstructorAttribute), false))
return MethodType.NativeCtor;
else if (imethod.Name.Equals ("Alloc"))
return MethodType.ManagedAlloc;
else if (imethod.IsDefined (typeof (DestructorAttribute), false))
return MethodType.NativeDtor;
return MethodType.Native;
}
示例15: AstReflectedMethod
public AstReflectedMethod(MethodInfo method)
{
Argument.RequireNotNull("method", method);
this.Method = method;
this.ReturnType = method.ReturnType != typeof(void)
? new AstReflectedType(method.ReturnType)
: (IAstTypeReference)AstVoidType.Instance;
this.ParameterTypes = method.GetParameters()
.Select(p => (IAstTypeReference)new AstReflectedType(p.ParameterType))
.ToArray()
.AsReadOnly();
this.Location = method.IsDefined<ExtensionAttribute>(false) ? MethodLocation.Extension : MethodLocation.Target;
}