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


C# MethodBase.GetCustomAttributes方法代码示例

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


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

示例1: ShouldWarn

        public static bool ShouldWarn(PythonBinder/*!*/ binder, MethodBase/*!*/ method, out WarningInfo info) {
            Assert.NotNull(method);

            ObsoleteAttribute[] os = (ObsoleteAttribute[])method.GetCustomAttributes(typeof(ObsoleteAttribute), true);
            if (os.Length > 0) {
                info = new WarningInfo(
                    PythonExceptions.DeprecationWarning,
                    String.Format("{0}.{1} has been obsoleted.  {2}",
                        NameConverter.GetTypeName(method.DeclaringType),
                        method.Name,
                        os[0].Message
                    )
                );

                return true;
            }

            if (binder.WarnOnPython3000) {
                Python3WarningAttribute[] py3kwarnings = (Python3WarningAttribute[])method.GetCustomAttributes(typeof(Python3WarningAttribute), true);
                if (py3kwarnings.Length > 0) {
                    info = new WarningInfo(
                        PythonExceptions.DeprecationWarning,
                        py3kwarnings[0].Message
                    );

                    return true;
                }
            }

#if !SILVERLIGHT
            // no apartment states on Silverlight
            if (method.DeclaringType == typeof(Thread)) {
                if (method.Name == "Sleep") {
                    info = new WarningInfo(
                        PythonExceptions.RuntimeWarning,
                        "Calling Thread.Sleep on an STA thread doesn't pump messages.  Use Thread.CurrentThread.Join instead.",
                        Expression.Equal(
                            Expression.Call(
                                Expression.Property(
                                    null,
                                    typeof(Thread).GetProperty("CurrentThread")
                                ),
                                typeof(Thread).GetMethod("GetApartmentState")
                            ),
                            AstUtils.Constant(ApartmentState.STA)
                        ),
                        () => Thread.CurrentThread.GetApartmentState() == ApartmentState.STA
                    );

                    return true;
                }
            }
#endif

            info = null;
            return false;
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:57,代码来源:BindingWarnings.cs

示例2: GetBaseName

 public string GetBaseName(MethodBase method, Func<DisplayAsAttribute, string> selectName)
 {
     var nameAttribute = method.GetCustomAttributes(typeof(DisplayAsAttribute), true);
     if(nameAttribute.Length != 0)
         return selectName(((DisplayAsAttribute)nameAttribute[0]));
     return NormalizeNamePattern.Replace(method.Name, " ");
 }
开发者ID:drunkcod,项目名称:Cone,代码行数:7,代码来源:ConeTestNamer.cs

示例3: MethodShouldBeProxied

        public bool MethodShouldBeProxied(MethodBase method, IList aspects, Type baseType)
        {
            foreach (IAspect aspect in aspects)
            {
                IGenericAspect tmpAspect;
                if (aspect is IGenericAspect)
                    tmpAspect = (IGenericAspect) aspect;
                else
                    tmpAspect = TypedToGenericConverter.Convert((ITypedAspect) aspect);

                foreach (IPointcut pointcut in tmpAspect.Pointcuts)
                {
                    if (pointcut.IsMatch(method, baseType))
                        return true;
                }
            }
            foreach (FixedInterceptorAttribute fixedInterceptorAttribute in method.GetCustomAttributes(typeof(FixedInterceptorAttribute), true))
                return true;

            if (baseType != null)
            {
                foreach (FixedInterceptorAttribute fixedInterceptorAttribute in baseType.GetCustomAttributes(typeof(FixedInterceptorAttribute), true))
                    return true;
            }

            return false;
        }
开发者ID:BackupTheBerlios,项目名称:puzzle-svn,代码行数:27,代码来源:PointcutMatcher.cs

示例4: GetMongoSessionAttribute

        private MongoSessionAttribute GetMongoSessionAttribute(MethodBase methodBase)
        {
            // �޼��忡 Ư���� �����Ǿ� �ִ��� Ȯ���Ѵ�.
            object[] attrs
                      = methodBase.GetCustomAttributes(typeof(MongoSessionAttribute), true);

            MongoSessionAttribute sessionAttribute = null;

            if (attrs != null && attrs.Length > 0)
            {
                sessionAttribute = (MongoSessionAttribute)attrs[0];
            }
            else
            {
                // Ŭ������ Ư���� �����Ǿ� �ִ��� Ȯ���Ѵ�.
                attrs = methodBase.ReflectedType.GetCustomAttributes(
                            typeof(MongoSessionAttribute), true);

                if (attrs != null && attrs.Length > 0)
                {
                    sessionAttribute = (MongoSessionAttribute)attrs[0];
                }
            }

            return sessionAttribute;
        }
开发者ID:tomochandv,项目名称:Test,代码行数:26,代码来源:MongoSessionProcessor.cs

示例5: WebAttributesOCEExtender

		static bool WebAttributesOCEExtender (MethodBase method, object[] customAttributes, ref OperationContractAttribute oca)
		{
			int caLength = customAttributes == null ? 0 : customAttributes.Length;
			if (method == null && caLength == 0)
				return false;

			if (caLength == 0) {
				customAttributes = method.GetCustomAttributes (false);

				if (customAttributes.Length == 0)
					return false;
			}

			bool foundWebAttribute = false;
			foreach (object o in customAttributes) {
				if (o is WebInvokeAttribute || o is WebGetAttribute) {
					foundWebAttribute = true;
					break;
				}
			}

			if (!foundWebAttribute)
				return false;

			// LAMESPEC: .NET allows for contract methods decorated only with
			// Web{Get,Invoke}Attribute and _without_ the OperationContractAttribute.
			if (oca == null)
				oca = new OperationContractAttribute ();
			
			return true;
		}
开发者ID:nickchal,项目名称:pash,代码行数:31,代码来源:WebScriptServiceHostFactory.cs

示例6: IsUnitTestMethod

        private static bool IsUnitTestMethod(MethodBase method)
        {
            // Look for NUnit [Test] attribute on method
            var testAttributes = method.GetCustomAttributes(typeof(TestAttribute), true);

            return testAttributes.Any();
        }
开发者ID:sybrix,项目名称:EdFi-App,代码行数:7,代码来源:FeatureTestMethodOverrideAspect.cs

示例7: GetOperationContractAttribute

			GetOperationContractAttribute (MethodBase method)
		{
			object [] matts = method.GetCustomAttributes (
				typeof (OperationContractAttribute), false);
			if (matts.Length == 0)
				return null;
			return (OperationContractAttribute) matts [0];
		}
开发者ID:jdecuyper,项目名称:mono,代码行数:8,代码来源:ContractDescriptionGenerator.cs

示例8: CompileTimeValidate

 public override bool CompileTimeValidate(MethodBase method)
 {
     return
         (method.GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Length == 0 &&
         !method.Name.StartsWith("get_") &&
         !method.Name.StartsWith("set_") &&
         !method.IsConstructor);
 }
开发者ID:elisabethf,项目名称:BlackBoxRecorder,代码行数:8,代码来源:DependencyAttribute.cs

示例9: Matches

        public bool Matches(MethodBase member)
        {
            Guard.ArgumentNotNull(member, "member");

            object[] attribues = member.GetCustomAttributes(attributeType, inherited);

            return (attribues != null && attribues.Length > 0);
        }
开发者ID:kangkot,项目名称:unity,代码行数:8,代码来源:CustomAttributeMatchingRule.cs

示例10: AddSnippet

        protected void AddSnippet(ServiceOutput output, MethodBase methodBase)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            if (methodBase == null)
            {
                throw new ArgumentNullException("methodBase");
            }

            // get the action associated with the call
            SnippetAction action = SnippetManager.Instance.Parse(HttpContext.Current.Request.Params);
            if (action.IsEnabled)
            {

                bool snippetMatch = false;

                //get the name of the snippet that needs to be loaded
                string snippetName = action.Name;

                // make sure the method can support this snippet.
                object[] attributes = methodBase.GetCustomAttributes(typeof(SupportedSnippetAttribute), false);
                foreach (object a in attributes)
                {
                    SupportedSnippetAttribute attribute = a as SupportedSnippetAttribute;
                    if (attribute != null &&
                        attribute.Name.Equals(attribute.Name, StringComparison.OrdinalIgnoreCase) )
                    {
                        snippetMatch = true;
                        break;
                    }
                }

                logger.Log(LogLevel.Debug, "SnippetName - [{0}] , Match - {1}", snippetName, snippetMatch);

                // asked snippet can be supported by the service.
                if (snippetMatch &&
                    SnippetManager.Instance.IsRegistered(snippetName))
                {
                    // load the snippet control from the location
                    Control control = FormlessPage.GetControl(SnippetManager.Instance.GetControlPath(snippetName));
                    SnippetControl snippet = control as SnippetControl;

                    if (snippet != null)
                    {
                        logger.Log(LogLevel.Debug, "Got snippet [{0}], invoking to get output.", snippetName);

                        //set the control values
                        snippet.SetProperties(action.Properties);
                        output.AddOutput(Constants.Json.Html, snippet.GetJsonHtml());
                    }
                }
            }
        }
开发者ID:ratnazone,项目名称:ratna,代码行数:56,代码来源:ServiceBase.cs

示例11: MethodMemberDescriptor

		/// <summary>
		/// Initializes a new instance of the <see cref="MethodMemberDescriptor"/> class.
		/// </summary>
		/// <param name="methodBase">The MethodBase (MethodInfo or ConstructorInfo) got through reflection.</param>
		/// <param name="accessMode">The interop access mode.</param>
		/// <exception cref="System.ArgumentException">Invalid accessMode</exception>
		public MethodMemberDescriptor(MethodBase methodBase, InteropAccessMode accessMode = InteropAccessMode.Default)
		{
			CheckMethodIsCompatible(methodBase, true);

			IsConstructor = (methodBase is ConstructorInfo);
			this.MethodInfo = methodBase;

			bool isStatic = methodBase.IsStatic || IsConstructor;

			if (IsConstructor)
				m_IsAction = false;
			else
				m_IsAction = ((MethodInfo)methodBase).ReturnType == typeof(void);

			ParameterInfo[] reflectionParams = methodBase.GetParameters();
			ParameterDescriptor[] parameters;
			
			if (this.MethodInfo.DeclaringType.IsArray)
			{
				m_IsArrayCtor = true;

				int rank = this.MethodInfo.DeclaringType.GetArrayRank();

				parameters = new ParameterDescriptor[rank];

				for (int i = 0; i < rank; i++)
					parameters[i] = new ParameterDescriptor("idx" + i.ToString(), typeof(int));
			}
			else
			{
				parameters = reflectionParams.Select(pi => new ParameterDescriptor(pi)).ToArray();
			}
		
			
			bool isExtensionMethod = (methodBase.IsStatic && parameters.Length > 0 && methodBase.GetCustomAttributes(typeof(ExtensionAttribute), false).Any());

			base.Initialize(methodBase.Name, isStatic, parameters, isExtensionMethod);

			// adjust access mode
			if (Script.GlobalOptions.Platform.IsRunningOnAOT())
				accessMode = InteropAccessMode.Reflection;

			if (accessMode == InteropAccessMode.Default)
				accessMode = UserData.DefaultAccessMode;

			if (accessMode == InteropAccessMode.HideMembers)
				throw new ArgumentException("Invalid accessMode");

			if (parameters.Any(p => p.Type.IsByRef))
				accessMode = InteropAccessMode.Reflection;

			this.AccessMode = accessMode;

			if (AccessMode == InteropAccessMode.Preoptimized)
				((IOptimizableDescriptor)this).Optimize();
		}
开发者ID:abstractmachine,项目名称:Fungus-3D-Template,代码行数:62,代码来源:MethodMemberDescriptor.cs

示例12: Matches

        public bool Matches(MethodBase member)
        {
            Guard.ArgumentNotNull(member, "member");

            bool hasNoPoliciesAttribute =
                (member.GetCustomAttributes(typeof(ApplyNoPoliciesAttribute), false).Length != 0);

            hasNoPoliciesAttribute |=
                (member.DeclaringType.GetCustomAttributes(typeof(ApplyNoPoliciesAttribute), false).
                    Length != 0);
            return !hasNoPoliciesAttribute;
        }
开发者ID:kangkot,项目名称:unity,代码行数:12,代码来源:ApplyNoPoliciesMatchingRule.cs

示例13: IsBoxedMath

        public static bool IsBoxedMath(MethodBase m)
        {
            Type t = m.DeclaringType;
            if ( t == typeof(Numbers))
            {
                object[] boxedMaths = m.GetCustomAttributes(typeof(WarnBoxedMathAttribute), true);
                if (boxedMaths.Length > 0)
                    return ((WarnBoxedMathAttribute)boxedMaths[0]).Value;

                ParameterInfo[] pis = ((MethodBase)m).GetParameters();
                foreach (ParameterInfo param in pis)
                    if (param.ParameterType.Equals(typeof(object)) )
                        return true;
            }

            return false;
        }
开发者ID:rvedam,项目名称:clojure-clr,代码行数:17,代码来源:StaticMethodExpr.cs

示例14: GetOperationContractAttribute

		public static OperationContractAttribute GetOperationContractAttribute (MethodBase method)
		{
			object [] matts = method.GetCustomAttributes (typeof (OperationContractAttribute), false);
			OperationContractAttribute oca;
			
			if (matts.Length == 0)
				oca = null;
			else
				oca = matts [0] as OperationContractAttribute;

			if (getOperationContractAttributeExtenders != null && getOperationContractAttributeExtenders.Count > 0) {
				foreach (var extender in getOperationContractAttributeExtenders)
					if (extender (method, matts, ref oca))
						break;
			}

			return oca;
		}
开发者ID:nekresh,项目名称:mono,代码行数:18,代码来源:ContractDescriptionGenerator.cs

示例15: MethodMemberDescriptor

        /// <summary>
        ///     Initializes a new instance of the <see cref="MethodMemberDescriptor" /> class.
        /// </summary>
        /// <param name="methodBase">The MethodBase (MethodInfo or ConstructorInfo) got through reflection.</param>
        /// <param name="accessMode">The interop access mode.</param>
        /// <exception cref="System.ArgumentException">Invalid accessMode</exception>
        public MethodMemberDescriptor(MethodBase methodBase, InteropAccessMode accessMode = InteropAccessMode.Default)
        {
            CheckMethodIsCompatible(methodBase, true);

            IsConstructor = (methodBase is ConstructorInfo);
            MethodInfo = methodBase;

            var isStatic = methodBase.IsStatic || IsConstructor;

            if (IsConstructor)
                m_IsAction = false;
            else
                m_IsAction = ((MethodInfo) methodBase).ReturnType == typeof (void);

            var reflectionParams = methodBase.GetParameters();
            var parameters = reflectionParams.Select(pi => new ParameterDescriptor(pi)).ToArray();

            var isExtensionMethod = (methodBase.IsStatic && parameters.Length > 0 &&
                                     methodBase.GetCustomAttributes(typeof (ExtensionAttribute), false).Any());

            Initialize(methodBase.Name, isStatic, parameters, isExtensionMethod);

            // adjust access mode
            if (Script.GlobalOptions.Platform.IsRunningOnAOT())
                accessMode = InteropAccessMode.Reflection;

            if (accessMode == InteropAccessMode.Default)
                accessMode = UserData.DefaultAccessMode;

            if (accessMode == InteropAccessMode.HideMembers)
                throw new ArgumentException("Invalid accessMode");

            if (parameters.Any(p => p.Type.IsByRef))
                accessMode = InteropAccessMode.Reflection;

            AccessMode = accessMode;

            if (AccessMode == InteropAccessMode.Preoptimized)
                ((IOptimizableDescriptor) this).Optimize();
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:46,代码来源:MethodMemberDescriptor.cs


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