当前位置: 首页>>代码示例>>C#>>正文


C# MethodInfo.IsDefined方法代码示例

本文整理汇总了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);
         }
     }
 }
开发者ID:VenoMpie,项目名称:DoomSharp,代码行数:28,代码来源:Registrar.cs

示例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;
        }
开发者ID:dafeifei0218,项目名称:aspnetboilerplate,代码行数:68,代码来源:AuditingHelper.cs

示例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;
        }
开发者ID:dw4dev,项目名称:Phalanger,代码行数:25,代码来源:Members.cs

示例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;
        }
开发者ID:zhongkai1010,项目名称:OneWork,代码行数:61,代码来源:AuditingHelper.cs

示例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;
        }
开发者ID:yuzukwok,项目名称:aspnetboilerplate,代码行数:53,代码来源:AuditingHelper.cs

示例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 ?? "";
        }
开发者ID:marinehero,项目名称:ThinkAway.net,代码行数:14,代码来源:ActionMethod.cs

示例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;
 }
开发者ID:balaghanta,项目名称:nunit-framework,代码行数:11,代码来源:ParameterizedMethodSuite.cs

示例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();
        }
开发者ID:sliplow,项目名称:LisaChowArtwork,代码行数:29,代码来源:DelegateFactory.cs

示例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;
        }
开发者ID:vytautask,项目名称:aspnetboilerplate,代码行数:34,代码来源:AbpAntiForgeryManagerWebExtensions.cs

示例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;
            }
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:45,代码来源:AttributeMethodMatcher.cs

示例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;
        }
开发者ID:vothlizard,项目名称:MVC.Template,代码行数:17,代码来源:AuthorizationProvider.cs

示例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));
        }
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:10,代码来源:ActionMethodSelector.cs

示例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);
        }
开发者ID:Kostassoid,项目名称:NProxy,代码行数:11,代码来源:NonInterceptedInterceptionFilter.cs

示例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;
		}
开发者ID:ctguxp,项目名称:cxxi,代码行数:15,代码来源:CppAbi.cs

示例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;
        }
开发者ID:izobr,项目名称:light,代码行数:15,代码来源:AstReflectedMethod.cs


注:本文中的System.Reflection.MethodInfo.IsDefined方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。