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


C# MethodInfo.GetCustomAttributes方法代码示例

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


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

示例1: CanBeUsedAsAction

    public static bool CanBeUsedAsAction(MethodInfo methodInfo, bool ignoreReturnType)
    {
        if (!methodInfo.IsPublic)
            return false;
        if (!ignoreReturnType && methodInfo.ReturnType != typeof(IEnumerator<React.NodeResult>))
            return false;
        if (methodInfo.GetParameters().Length != 0)
        {
            if (methodInfo.GetCustomAttributes(typeof(React.ReactActionAttribute), true).Length == 0)
                return false;
        }

        return true;
    }
开发者ID:s76,项目名称:testAI,代码行数:14,代码来源:Reactable.cs

示例2: BuildMethodString

 public static string BuildMethodString(ref MethodInfo method)
 {
     string empty = string.Empty;
     string str = "no help";
     object[] customAttributes = method.GetCustomAttributes(true);
     for (int i = 0; i < (int)customAttributes.Length; i++)
     {
         object obj = customAttributes[i];
         if (obj is ConsoleSystem.Help)
         {
             empty = (obj as ConsoleSystem.Help).argsDescription;
             str = (obj as ConsoleSystem.Help).helpDescription;
             empty = string.Concat(" ", empty.Trim(), " ");
         }
     }
     return string.Concat(new string[] { method.Name, "(", empty, ") : ", str });
 }
开发者ID:HexHash,项目名称:LegacyRust,代码行数:17,代码来源:global.cs

示例3: CheckFlags

	 static void CheckFlags (PropertyInfo pi, MethodInfo accessor)
	 {
		 object [] attrs = accessor.GetCustomAttributes (typeof (AccessorCheckAttribute), true);
		 if (attrs == null)
			 return;

		 AccessorCheckAttribute accessor_attr = (AccessorCheckAttribute) attrs [0];
		 MethodAttributes accessor_flags = accessor.Attributes;

		 if ((accessor_flags & accessor_attr.Attributes) == accessor_attr.Attributes)
			 Console.WriteLine ("Test for {0}.{1} PASSED", pi.Name, accessor.Name);
		 else {
			 string message = String.Format ("Test for {0}.{1} INCORRECT: MethodAttributes should be {2}, but are {3}",
					 pi.Name, accessor.Name, accessor_attr.Attributes, accessor_flags);
			 throw new Exception (message);
		 }
	 }
开发者ID:nobled,项目名称:mono,代码行数:17,代码来源:test-397.cs

示例4: GetMethodName

    static string GetMethodName(MethodInfo md)
    {
        if (md.Name.StartsWith("op_"))
        {
            return md.Name;
        }

        object[] attrs = md.GetCustomAttributes(true);

        for (int i = 0; i < attrs.Length; i++)
        {
            if (attrs[i] is LuaRenameAttribute)
            {
                LuaRenameAttribute attr = attrs[i] as LuaRenameAttribute;
                return attr.Name;
            }
        }

        return md.Name;
    }
开发者ID:xlwangcs,项目名称:LuaFramework_UGUI,代码行数:20,代码来源:ToLuaExport.cs

示例5: ValidateAnnotations

    private static void ValidateAnnotations(MethodInfo method, bool noValidate = false)
    {
        Dictionary<string, ParameterInfo> methodParams = method.GetParameters()
            .ToDictionary(m => m.Name);

        TeakLinkAttribute[] teakLinks = method.GetCustomAttributes(typeof(TeakLinkAttribute), false) as TeakLinkAttribute[];
        foreach(TeakLinkAttribute link in teakLinks)
        {
            // https://github.com/rkh/mustermann/blob/master/mustermann-simple/lib/mustermann/simple.rb
            Regex escape = new Regex(@"[^\?\%\\\/\:\*\w]");
            string pattern = escape.Replace(link.Url, (Match m) => {
                return Regex.Escape(m.Value);
            });

            List<string> dupeCheck = new List<string>();
            Regex compile = new Regex(@"((:\w+)|\*)");
            pattern = compile.Replace(pattern, (Match m) => {
                if(m.Value == "*")
                {
                    // 'splat' behavior could be bad to support from a debugging standpoint
                    throw new NotSupportedException(String.Format("'splat' functionality is not supported by TeakLinks.\nMethod: {0}", DebugStringForMethodInfo(method)));
                    // return "(?<splat>.*?)";
                }
                 dupeCheck.Add(m.Value.Substring(1));
                return String.Format("(?<{0}>[^/?#]+)", m.Value.Substring(1));
            });

            if(!noValidate)
            {
                // Check for duplicate capture group names
                List<string> duplicates = dupeCheck
                    .GroupBy(i => i)
                    .Where(g => g.Count() > 1)
                    .Select(g => g.Key)
                    .ToList();
                if(duplicates.Count() > 0)
                {
                    throw new ArgumentException(String.Format("Duplicate variable name '{0}'.\nMethod: {1}", duplicates[0], DebugStringForMethodInfo(method)));
                }
            }

            link.Regex = new Regex(pattern);
            link.MethodParams = methodParams;
            link.MethodInfo = method;

            if(!noValidate)
            {
                // Check for special case where method has only one parameter named 'params' of type Dictionary<string, object>
                if(link.MethodParams.ContainsKey("parameters"))
                {
                    if(link.MethodParams["parameters"].ParameterType != typeof(Dictionary<string, object>))
                    {
                        throw new ArgumentException(String.Format("Parameter passing by 'parameters' must use type Dictionary<string, object>.\nMethod: {0}", DebugStringForMethodInfo(method)));
                    }
                }
                else
                {
                    foreach(string groupName in link.Regex.GetGroupNames())
                    {
                        if(groupName == "0") continue;
                        if(!link.MethodParams.ContainsKey(groupName))
                        {
                            throw new ArgumentException(String.Format("TeakLink missing parameter name '{0}'\nMethod: {1}", groupName, DebugStringForMethodInfo(method)));
                        }
                    }
                }
            }

            // Check for either static method or method on a MonoBehaviour
            if(method.IsStatic)
            {
                // Nothing for now
            }
            else if(method.DeclaringType.BaseType == typeof(MonoBehaviour)) // TODO: Walk back base types?
            {
                link.DeclaringObjectType = method.DeclaringType;
            }
            else
            {
                Debug.LogError(method.DeclaringType + " is a " + method.DeclaringType.BaseType);
                throw new NotSupportedException(String.Format("Method must be declared 'static' if it is not on a MonoBehaviour.\nMethod: {0}", DebugStringForMethodInfo(method)));
            }

            if(!noValidate)
            {
                // Check for duplicate routes
                string dupeRouteCheck = link.Url;
                foreach(string groupName in link.Regex.GetGroupNames())
                {
                    if(groupName == "0") continue;
                    dupeRouteCheck = dupeRouteCheck.Replace(String.Format(":{0}", groupName), "");
                }

                foreach(KeyValuePair<Regex, TeakLinkAttribute> entry in TeakLinkAttribute.Links)
                {
                    string emptyVarRoute = entry.Value.Url;
                    foreach(string groupName in entry.Key.GetGroupNames())
                    {
                        if(groupName == "0") continue;
                        emptyVarRoute = emptyVarRoute.Replace(String.Format(":{0}", groupName), "");
//.........这里部分代码省略.........
开发者ID:GoCarrot,项目名称:teak-unity,代码行数:101,代码来源:TeakLinkAttribute.cs

示例6: IsRunnableKoan

 private static bool IsRunnableKoan(MethodInfo method)
 {
     return method.GetCustomAttributes(false).Count(attribute =>
            attribute.GetType().FullName == typeof(KoanAttribute).FullName
         && !((KoanAttribute)attribute).Ignore
         ) != 0;
 }
开发者ID:psrodriguez,项目名称:CIAPI.CS,代码行数:7,代码来源:Program.cs

示例7: CheckExceptions

    private void CheckExceptions(MethodInfo m)
    {
        ShouldThrowExceptionAttribute[] attrs = (ShouldThrowExceptionAttribute[])m.GetCustomAttributes(typeof(ShouldThrowExceptionAttribute), true);
        ArrayList allowedExceptionTypes = null;
        if(attrs.Length > 0) {
          allowedExceptionTypes = new ArrayList();
          foreach(ShouldThrowExceptionAttribute s in attrs)
        allowedExceptionTypes.Add(s.allowedExceptionType);
        }

        bool wantException = (allowedExceptionTypes != null) && (allowedExceptionTypes.Count > 0);
        bool gotException = exceptionThrown != null;

        if(wantException && gotException) {
          bool gotRightKindOfException = false;
          foreach(System.Type et in allowedExceptionTypes) {
        if(et.IsAssignableFrom(exceptionThrown.GetType())) {
          gotRightKindOfException = true;
          break;
        }
          }
          if(!gotRightKindOfException) {
        // FAIL.
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("Expected one type of exception, but got another.  Expected one of:");
        foreach(System.Type tt in allowedExceptionTypes)
          sb.Append(" ").Append(tt.Name);
        _Fail(sb.ToString(), exceptionThrown);
          }
        } else if(wantException && !gotException) {
          // FAIL.
          _Fail("Expected an exception, but did not get one.");
        } else if(!wantException && gotException) {
          // FAIL.
          _Fail("Unexpected exception.", exceptionThrown);
        }
    }
开发者ID:MrJoy,项目名称:UnityTest,代码行数:37,代码来源:UnityTest.cs

示例8: CheckPermission

            private static void CheckPermission(List<ReadonlyItem> inspectorOwnedAction, List<MethodInfo> invalidActions, MethodInfo method)
            {
                var permission = inspectorOwnedAction.Find(x => x.ActionName.EqualsOrdinalIgnoreCase(method.Name));
                if (permission != null)
                {
                    if (permission.HttpMethod != null)
                    {
                        var currentMethodAttributes = method.GetCustomAttributes(false).ToList();

                        var isInvalid = currentMethodAttributes.Find(x => x.ToString().EqualsOrdinalIgnoreCase(permission.HttpMethod.FullName)) == null;

                        if (isInvalid) invalidActions.Add(method);
                    }
                }
                else
                {
                    invalidActions.Add(method);
                }
            }
开发者ID:itabas016,项目名称:AppStores,代码行数:19,代码来源:AppStoresUIControllerTest.cs

示例9: ProcessDefinition

            public bool ProcessDefinition(MethodInfo method, out object instance)
            {
                instance = null;

			    string objectName = method.Name;

                if (objectName.StartsWith("set_") || objectName.StartsWith("get_"))
                {
                    return false;
                }

                object[] attribs = method.GetCustomAttributes(typeof(ObjectDefAttribute), true);
                if (attribs.Length == 0)
                {
                    return false;
                }

                if (this._configurableListableObjectFactory.IsCurrentlyInCreation(objectName))
                {
                    Logger.Debug(m => m("Object '{0}' currently in creation, created one", objectName));

                    return false;
                }

                Logger.Debug(m => m("Object '{0}' not in creation, asked the application context for one", objectName)); 

                instance = this._configurableListableObjectFactory.GetObject(objectName);
                return true;
            }
开发者ID:Binodesk,项目名称:spring-net,代码行数:29,代码来源:ConfigurationClassEnhancer.cs

示例10: GetMethodAttributes

        /// <summary>
        /// Calculates and returns the list of attributes that apply to the
        /// specified method.
        /// </summary>
        /// <param name="method">The method to find attributes for.</param>
        /// <returns>
        /// A list of custom attributes that should be applied to method.
        /// </returns>
        /// <see cref="IProxyTypeBuilder.ProxyTargetAttributes"/>
        /// <see cref="IProxyTypeBuilder.MemberAttributes"/>
        protected virtual IList GetMethodAttributes(MethodInfo method)
        {
            ArrayList attributes = new ArrayList();

            if (this.ProxyTargetAttributes)
            {
                // add attributes that apply to the target method
#if NET_2_0
                object[] attrs = method.GetCustomAttributes(false);
                try
                {
                    System.Collections.Generic.IList<CustomAttributeData> attrsData = 
                        CustomAttributeData.GetCustomAttributes(method);
                    
                    if (attrs.Length != attrsData.Count)
                    {
                        // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94803
                        attributes.AddRange(attrs);
                    }
                    else
                    {
                        foreach (CustomAttributeData cad in attrsData)
                        {
                            attributes.Add(cad);
                        }
                    }
                }
                catch (ArgumentException)
                {
                    // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=296032
                    attributes.AddRange(attrs);
                }
#else
                attributes.AddRange(method.GetCustomAttributes(false));
#endif
            }

            // add attributes defined by configuration
            foreach (DictionaryEntry entry in MemberAttributes)
            {
                if (TypeResolutionUtils.MethodMatch((string)entry.Key, method))
                {
                    if (entry.Value is Attribute)
                    {
                        attributes.Add(entry.Value);
                    }
                    else if (entry.Value is IList)
                    {
                        attributes.AddRange(entry.Value as IList);
                    }
                }
            }

            return attributes;
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:65,代码来源:AbstractProxyTypeBuilder.cs


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