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


C# RuntimeMethodInfo.GetGenericMethodDefinition方法代码示例

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


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

示例1: GetCustomAttributes

        [System.Security.SecurityCritical]  // auto-generated
        internal static Object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
        {
            Contract.Requires(method != null);
            Contract.Requires(caType != null);

            if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
                method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;

            int pcaCount = 0;
            Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out pcaCount);

            // if we are asked to go up the hierarchy chain we have to do it now and regardless of the
            // attribute usage for the specific attribute because a derived attribute may override the usage...           
            // ... however if the attribute is sealed we can rely on the attribute usage
            if (!inherit || (caType.IsSealed && !CustomAttribute.GetAttributeUsage(caType).Inherited))
            {
                object[] attributes = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, pcaCount, caType, !AllowCriticalCustomAttributes(method));
                if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
                return attributes;
            }

            List<object> result = new List<object>();
            bool mustBeInheritable = false;
            bool useObjectArray = (caType == null || caType.IsValueType || caType.ContainsGenericParameters);
            Type arrayType = useObjectArray ? typeof(object) : caType;

            while (pcaCount > 0) 
                result.Add(pca[--pcaCount]);
                
            while (method != null)
            {
                object[] attributes = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, result, !AllowCriticalCustomAttributes(method));
                mustBeInheritable = true;
                for (int i = 0; i < attributes.Length; i++)
                    result.Add(attributes[i]);

                method = method.GetParentDefinition();
            }

            object[] typedResult = CreateAttributeArrayHelper(arrayType, result.Count);
            Array.Copy(result.ToArray(), 0, typedResult, 0, result.Count);
            return typedResult;
        }
开发者ID:enavro,项目名称:coreclr,代码行数:44,代码来源:CustomAttribute.cs

示例2: GetCustomAttributes

 internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
 {
     if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
     {
         method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;
     }
     int count = 0;
     Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out count);
     if (!inherit || (caType.IsSealed && !GetAttributeUsage(caType).Inherited))
     {
         object[] objArray = GetCustomAttributes(method.Module, method.MetadataToken, count, caType);
         if (count > 0)
         {
             Array.Copy(sourceArray, 0, objArray, objArray.Length - count, count);
         }
         return objArray;
     }
     List<object> derivedAttributes = new List<object>();
     bool mustBeInheritable = false;
     Type elementType = (((caType == null) || caType.IsValueType) || caType.ContainsGenericParameters) ? typeof(object) : caType;
     while (count > 0)
     {
         derivedAttributes.Add(sourceArray[--count]);
     }
     while (method != null)
     {
         object[] objArray2 = GetCustomAttributes(method.Module, method.MetadataToken, 0, caType, mustBeInheritable, derivedAttributes);
         mustBeInheritable = true;
         for (int i = 0; i < objArray2.Length; i++)
         {
             derivedAttributes.Add(objArray2[i]);
         }
         method = method.GetParentDefinition() as RuntimeMethodInfo;
     }
     object[] destinationArray = Array.CreateInstance(elementType, derivedAttributes.Count) as object[];
     Array.Copy(derivedAttributes.ToArray(), 0, destinationArray, 0, derivedAttributes.Count);
     return destinationArray;
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:38,代码来源:CustomAttribute.cs


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