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


C# MethodInfo.GetCustomAttributes方法代码示例

本文整理汇总了C#中System.Reflection.MethodInfo.GetCustomAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.GetCustomAttributes方法的具体用法?C# MethodInfo.GetCustomAttributes怎么用?C# MethodInfo.GetCustomAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.MethodInfo的用法示例。


在下文中一共展示了MethodInfo.GetCustomAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtendsType

        public static bool ExtendsType(MethodInfo method, Type type)
        {
            var ext = method.GetCustomAttributes(typeof(ExtendsAttribute), true);

            if (ext.Length != 0 && ((ExtendsAttribute)ext[0]).Type == type)
            {
                return true;
            }

            if (method.GetCustomAttributes(typeof(ExtensionAttribute), true).Length == 0)
            {
                return false;
            }

            var pars = method.GetParameters();
            if (pars.Length == 0)
            {
                return false;
            }

            if (type != pars[0].ParameterType)
            {
                // maybe test for subclass
                return false;
            }

            return true;
        }
开发者ID:jantolenaar,项目名称:kiezellisp,代码行数:28,代码来源:clr.cs

示例2: Scan

        public IEnumerable<ExecutionStep> Scan(object testObject, MethodInfo candidateMethod)
        {
            var executableAttribute = (ExecutableAttribute)candidateMethod.GetCustomAttributes(typeof(ExecutableAttribute), false).FirstOrDefault();
            if(executableAttribute == null)
                yield break;

            string stepTitle = executableAttribute.StepTitle;
            if(string.IsNullOrEmpty(stepTitle))
                stepTitle = NetToString.Convert(candidateMethod.Name);

            var stepAsserts = IsAssertingByAttribute(candidateMethod);

            var runStepWithArgsAttributes = (RunStepWithArgsAttribute[])candidateMethod.GetCustomAttributes(typeof(RunStepWithArgsAttribute), false);
            if (runStepWithArgsAttributes.Length == 0)
            {
                yield return new ExecutionStep(GetStepAction(candidateMethod), stepTitle, stepAsserts, executableAttribute.ExecutionOrder, true);
            }

            foreach (var runStepWithArgsAttribute in runStepWithArgsAttributes)
            {
                var inputArguments = runStepWithArgsAttribute.InputArguments;
                var flatInput = inputArguments.FlattenArrays();
                var stringFlatInputs = flatInput.Select(i => i.ToString()).ToArray();
                var methodName = stepTitle + " " + string.Join(", ", stringFlatInputs);

                if (!string.IsNullOrEmpty(runStepWithArgsAttribute.StepTextTemplate))
                    methodName = string.Format(runStepWithArgsAttribute.StepTextTemplate, flatInput);
                else if (!string.IsNullOrEmpty(executableAttribute.StepTitle))
                    methodName = string.Format(executableAttribute.StepTitle, flatInput);

                yield return new ExecutionStep(GetStepAction(candidateMethod, inputArguments), methodName, stepAsserts, executableAttribute.ExecutionOrder, true);
            }
        }
开发者ID:droyad,项目名称:TestStack.BDDfy,代码行数:33,代码来源:ExecutableAttributeStepScanner.cs

示例3: FromMethodInfo

        /// <summary>
        /// Returns a ClientMethod instance to get the name of the class and method name on the client-side JavaScript.
        /// </summary>
        /// <param name="method">The MethodInfo.</param>
        /// <returns>
        /// Returns the ClientMethod info, if it is not a AjaxMethod it will return null.
        /// </returns>
		public static ClientMethod FromMethodInfo(MethodInfo method)
		{
			if(method.GetCustomAttributes(typeof(AjaxPro.AjaxMethodAttribute), true).Length == 0)
				return null;

			AjaxPro.AjaxNamespaceAttribute[] classns = (AjaxPro.AjaxNamespaceAttribute[])method.ReflectedType.GetCustomAttributes(typeof(AjaxPro.AjaxNamespaceAttribute), true);
			AjaxPro.AjaxNamespaceAttribute[] methodns = (AjaxPro.AjaxNamespaceAttribute[])method.GetCustomAttributes(typeof(AjaxPro.AjaxNamespaceAttribute), true);

			ClientMethod cm = new ClientMethod();

			if (classns.Length > 0)
				cm.ClassName = classns[0].ClientNamespace;
			else
			{
				if (Utility.Settings.UseSimpleObjectNaming)
					cm.ClassName = method.ReflectedType.Name;
				else
					cm.ClassName = method.ReflectedType.FullName;
			}

			if(methodns.Length > 0)
				cm.MethodName += methodns[0].ClientNamespace;
			else
				cm.MethodName += method.Name;

			return cm;
		}
开发者ID:joethinh,项目名称:nohros-must,代码行数:34,代码来源:ClientMethod.cs

示例4: PublicMethod_ThatReturnsReferenceType_MustBeTaggedWithNotNullOrCanBeNullAttributes

        public void PublicMethod_ThatReturnsReferenceType_MustBeTaggedWithNotNullOrCanBeNullAttributes(MethodInfo method)
        {
            bool hasNotNullAttribute = method.GetCustomAttributes(typeof(NotNullAttribute), true).Any();
            bool hasCanBeNullAttribute = method.GetCustomAttributes(typeof(CanBeNullAttribute), true).Any();

            Assume.That(method.DeclaringType != null);
            Assert.That(hasNotNullAttribute || hasCanBeNullAttribute, "Method " + method.Name + " of type " + method.DeclaringType.Name + " must be tagged with [NotNull] or [CanBeNull]");
        }
开发者ID:modulexcite,项目名称:commander,代码行数:8,代码来源:NullableTypeTests.cs

示例5: GetMethods

 private static string[] GetMethods(MethodInfo methodInfo)
 {
     var list = new List<string>();
     list.AddRange(from customAttribute in methodInfo.GetCustomAttributes<HttpGetAttribute>() from httpMethod in customAttribute.HttpMethods select httpMethod.Method);
     list.AddRange(from customAttribute in methodInfo.GetCustomAttributes<HttpPostAttribute>() from httpMethod in customAttribute.HttpMethods select httpMethod.Method);
     list.AddRange(from customAttribute in methodInfo.GetCustomAttributes<HttpPutAttribute>() from httpMethod in customAttribute.HttpMethods select httpMethod.Method);
     list.AddRange(from customAttribute in methodInfo.GetCustomAttributes<HttpDeleteAttribute>() from httpMethod in customAttribute.HttpMethods select httpMethod.Method);
     return list.Distinct().ToArray();
 }
开发者ID:Apozhidaev,项目名称:WebApiDoc,代码行数:9,代码来源:DocHelper.cs

示例6: ParameterizedTestMethod

 public ParameterizedTestMethod(TestFixture testFixture, MethodInfo methodInfo)
    : base(testFixture, methodInfo) {
    foreach(DataRow dataRow in methodInfo.GetCustomAttributes(typeof(DataRow), true)) {
       _dataSource.Add(dataRow);
    }
    if(_dataSource.Count == 0) {
       object[] attrs = methodInfo.GetCustomAttributes(typeof(DataSourceAttribute), true);
       if( attrs.Length > 0 ) {
          _dataSource.Add(attrs[0] as DataSourceAttribute);
       }
    }
    _expectedParameterNum = MethodInfo.GetParameters().Length;
 }
开发者ID:ManfredLange,项目名称:csUnit,代码行数:13,代码来源:ParameterizedTestMethod.cs

示例7: 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

示例8: IsWebMethod

 public static bool IsWebMethod(MethodInfo method)
 {
     object[] customAttributes = method.GetCustomAttributes(typeof(SoapRpcMethodAttribute), true);
     if ((customAttributes != null) && (customAttributes.Length > 0))
     {
         return true;
     }
     customAttributes = method.GetCustomAttributes(typeof(SoapDocumentMethodAttribute), true);
     if ((customAttributes != null) && (customAttributes.Length > 0))
     {
         return true;
     }
     customAttributes = method.GetCustomAttributes(typeof(HttpMethodAttribute), true);
     return ((customAttributes != null) && (customAttributes.Length > 0));
 }
开发者ID:nkarastamatis,项目名称:WebServiceTestStudio_Winforms,代码行数:15,代码来源:WsdlModel.cs

示例9: RegisterMethod

 private static void RegisterMethod(MethodInfo method)
 {
     foreach (ScriptableAttribute attribute in method.GetCustomAttributes(typeof(ScriptableAttribute),false))
     {
         globalmethods[attribute.Name ?? method.Name] = method;
     }
 }
开发者ID:VenoMpie,项目名称:DoomSharp,代码行数:7,代码来源:DefinitionContext.cs

示例10: GetAttributes

        private List<MethodBoundaryAttribute> GetAttributes(MethodInfo methodInfo)
        {
            List<MethodBoundaryAttribute> attributes = new List<MethodBoundaryAttribute>();

            //Method level attributes
            MethodBoundaryAttribute[] methodAttributes = (MethodBoundaryAttribute[])methodInfo.GetCustomAttributes(typeof(MethodBoundaryAttribute), false);

            //Class level attributes
            MethodBoundaryAttribute[] classAttributes = (MethodBoundaryAttribute[])methodInfo.ReflectedType.GetCustomAttributes(typeof(MethodBoundaryAttribute), false);

            //add method level
            attributes.AddRange(methodAttributes);

            //add class attribute if not exist in method
            foreach (MethodBoundaryAttribute classAttr in classAttributes)
            {
                bool exist = false;
                foreach (MethodBoundaryAttribute methodAttr in methodAttributes)
                {
                    if (classAttr.TypeId == methodAttr.TypeId)
                        exist = true;
                }
                if (!exist)
                    attributes.Add(classAttr);
            }

            return attributes;
        }
开发者ID:tzaavi,项目名称:AOP.Castle,代码行数:28,代码来源:MethodBoundaryInterceptor.cs

示例11: CollectFilters

		/// <summary>
		/// Implementors should collect the transformfilter information
		/// and return descriptors instances, or an empty array if none
		/// was found.
		/// </summary>
		/// <param name="methodInfo">The action (MethodInfo)</param>
		/// <returns>
		/// An array of <see cref="TransformFilterDescriptor"/>
		/// </returns>
		public TransformFilterDescriptor[] CollectFilters(MethodInfo methodInfo)
		{
			if (logger.IsDebugEnabled)
			{
				logger.DebugFormat("Collecting transform filters for {0}", methodInfo.Name);
			}

			var attributes = methodInfo.GetCustomAttributes(typeof(ITransformFilterDescriptorBuilder), true);

			var filters = new List<TransformFilterDescriptor>();

			foreach(ITransformFilterDescriptorBuilder builder in attributes)
			{
				var descs = builder.BuildTransformFilterDescriptors();

				if (logger.IsDebugEnabled)
				{
					foreach(var desc in descs)
					{
						logger.DebugFormat("Collected transform filter {0} to execute in order {1}", desc.TransformFilterType, desc.ExecutionOrder);
					}
				}

				filters.AddRange(descs);
			}

			return filters.ToArray();
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:37,代码来源:DefaultTransformFilterDescriptorProvider.cs

示例12: runMethodTest

        TestResultBitmap runMethodTest(object instance, MethodInfo method)
        {
            if (method.IsGenericMethod)
                throw new Exception("{0}: is not allowed to be generic".format(method));

            var parameters = method.GetParameters();
            if (parameters.Length != 1)
                throw new Exception("{0}: expect one parameter".format(method));

            var firstParameter = parameters[0];
            if (firstParameter.ParameterType != typeof(IDrawingContext))
                throw new Exception("{0}: expect IDrawingContext as first and only parameter");

            var attribute = (BitmapDrawingTestAttribute)method.GetCustomAttributes(typeof (BitmapDrawingTestAttribute), false)[0];

            using (var context = new BitmapDrawingContext(attribute.Width, attribute.Height))
            {
                IDrawingContext drawingContext;
                using (context.beginDraw(out drawingContext))
                {
                    method.Invoke(instance, new object[] { drawingContext });
                }

                return new TestResultBitmap(attribute.Width, attribute.Height, context.extractRawBitmap());
            }
        }
开发者ID:fundeveloper,项目名称:CrossUI,代码行数:26,代码来源:TestRunner.cs

示例13: GetMethodGenerator

        public IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method)
        {
            IHqlGeneratorForMethod methodGenerator;

            if (method.IsGenericMethod)
            {
                method = method.GetGenericMethodDefinition();
            }

            if (_registeredMethods.TryGetValue(method, out methodGenerator))
            {
                return methodGenerator;
            }

            // No method generator registered.  Look to see if it's a standard LinqExtensionMethod
            var attr = method.GetCustomAttributes(typeof (LinqExtensionMethodAttribute), false);
            if (attr.Length == 1)
            {
                // It is
                // TODO - cache this?  Is it worth it?
                return new HqlGeneratorForExtensionMethod((LinqExtensionMethodAttribute) attr[0], method);
            }

            // Not that either.  Let's query each type generator to see if it can handle it
            foreach (var typeGenerator in _typeGenerators)
            {
                if (typeGenerator.SupportsMethod(method))
                {
                    return typeGenerator.GetMethodGenerator(method);
                }
            }

            throw new NotSupportedException(method.ToString());
        }
开发者ID:paulbatum,项目名称:nhibernate,代码行数:34,代码来源:FunctionRegistry.cs

示例14: MustAuthenticate

        public bool MustAuthenticate(Type type, MethodInfo method)
        {
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");

            return method.GetCustomAttributes(typeof(AuthenticateAttribute), false).Any();
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:7,代码来源:AuthenticateAttributeStrategy.cs

示例15: GetCombinations

        private static IEnumerable<VariantAttribute> GetCombinations(MethodInfo method)
        {
            var methodVariants
                = method
                    .GetCustomAttributes(typeof(VariantAttribute), true)
                    .Cast<VariantAttribute>()
                    .ToList();

            if (methodVariants.Any())
            {
                return methodVariants;
            }

            var typeVariants
                = method.DeclaringType
                    .GetCustomAttributes(typeof(VariantAttribute), true)
                    .Cast<VariantAttribute>()
                    .ToList();

            if (typeVariants.Any())
            {
                return typeVariants;
            }

            return new[] { new VariantAttribute(DatabaseProvider.SqlClient, ProgrammingLanguage.CSharp) };
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:26,代码来源:MigrationsTheoryAttribute.cs


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