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


C# ITypeInfo.GetCustomAttributes方法代码示例

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


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

示例1: Initialize

        void Initialize(ITestCollection testCollection, IAssemblyInfo assembly, ITypeInfo type, IMethodInfo method, IAttributeInfo factAttribute, object[] arguments)
        {
            string displayNameBase = factAttribute.GetNamedArgument<string>("DisplayName") ?? type.Name + "." + method.Name;
            ITypeInfo[] resolvedTypes = null;

            if (arguments != null && method.IsGenericMethodDefinition)
            {
                resolvedTypes = ResolveGenericTypes(method, arguments);
                method = method.MakeGenericMethod(resolvedTypes);
            }

            Assembly = assembly;
            Class = type;
            Method = method;
            Arguments = arguments;
            DisplayName = GetDisplayNameWithArguments(displayNameBase, arguments, resolvedTypes);
            SkipReason = factAttribute.GetNamedArgument<string>("Skip");
            Traits = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
            TestCollection = testCollection;

            foreach (IAttributeInfo traitAttribute in Method.GetCustomAttributes(typeof(TraitAttribute))
                                                            .Concat(Class.GetCustomAttributes(typeof(TraitAttribute))))
            {
                var ctorArgs = traitAttribute.GetConstructorArguments().ToList();
                Traits.Add((string)ctorArgs[0], (string)ctorArgs[1]);
            }

            uniqueID = new Lazy<string>(GetUniqueID, true);
        }
开发者ID:valmaev,项目名称:xunit,代码行数:29,代码来源:XunitTestCase.cs

示例2: Get

        /// <inheritdoc/>
        public ITestCollection Get(ITypeInfo testClass)
        {
            var collectionAttribute = testClass.GetCustomAttributes(typeof(CollectionAttribute)).SingleOrDefault();
            if (collectionAttribute == null)
                return defaultCollection;

            var collectionName = (string)collectionAttribute.GetConstructorArguments().First();
            return testCollections.GetOrAdd(collectionName, CreateTestCollection);
        }
开发者ID:kouweizhong,项目名称:xunit,代码行数:10,代码来源:CollectionPerAssemblyTestCollectionFactory.cs

示例3: GetRunWith

        public static ITypeInfo GetRunWith(ITypeInfo type)
        {
            foreach (IAttributeInfo attributeInfo in type.GetCustomAttributes(typeof(RunWithAttribute)))
            {
                RunWithAttribute attribute = attributeInfo.GetInstance<RunWithAttribute>();
                if (attribute == null || attribute.TestClassCommand == null)
                    continue;

                ITypeInfo typeInfo = Reflector.Wrap(attribute.TestClassCommand);
                if (ImplementsITestClassCommand(typeInfo))
                    return typeInfo;
            }

            return null;
        }
开发者ID:paulecoyote,项目名称:xunit,代码行数:15,代码来源:TypeUtility.cs

示例4: GetFixtureBuilderAttributes

        /// <summary>
        /// We look for attributes implementing IFixtureBuilder at one level 
        /// of inheritance at a time. Attributes on base classes are not used 
        /// unless there are no fixture builder attributes at all on the derived
        /// class. This is by design.
        /// </summary>
        /// <param name="typeInfo">The type being examined for attributes</param>
        /// <returns>A list of the attributes found.</returns>
        private IFixtureBuilder[] GetFixtureBuilderAttributes(ITypeInfo typeInfo)
        {
            IFixtureBuilder[] attrs = new IFixtureBuilder[0];

            while (typeInfo != null && !typeInfo.IsType(typeof(object)))
            {
                attrs = typeInfo.GetCustomAttributes<IFixtureBuilder>(false);

                if (attrs.Length > 0)
                {
                    // We want to eliminate duplicates that have no args.
                    // If there is just one, no duplication is possible.
                    if (attrs.Length == 1)
                        return attrs;

                    // Count how many have arguments
                    int withArgs = 0;
                    foreach (var attr in attrs)
                        if (HasArguments(attr))
                            withArgs++;

                    // If all have args, just return them
                    if (withArgs == attrs.Length)
                        return attrs;

                    // If none of them have args, return the first one
                    if (withArgs == 0)
                        return new IFixtureBuilder[] { attrs[0] };
                    
                    // Some of each - extract those with args
                    var result = new IFixtureBuilder[withArgs];
                    int count = 0;
                    foreach (var attr in attrs)
                        if (HasArguments(attr))
                            result[count++] = attr;

                    return result;
                }

                typeInfo = typeInfo.BaseType;
            }

            return attrs;
        }
开发者ID:textmetal,项目名称:main,代码行数:52,代码来源:DefaultSuiteBuilder.cs

示例5: GetValidHtmlTargetElementAttributes

        private static IEnumerable<HtmlTargetElementAttribute> GetValidHtmlTargetElementAttributes(
            ITypeInfo typeInfo,
            ErrorSink errorSink)
        {
            var targetElementAttributes = typeInfo.GetCustomAttributes<HtmlTargetElementAttribute>();

            return targetElementAttributes.Where(
                attribute => ValidHtmlTargetElementAttributeNames(attribute, errorSink));
        }
开发者ID:huoxudong125,项目名称:Razor,代码行数:9,代码来源:TagHelperDescriptorFactory.cs

示例6: GetAllowedChildren

        private static IEnumerable<string> GetAllowedChildren(ITypeInfo typeInfo, ErrorSink errorSink)
        {
            var restrictChildrenAttribute = typeInfo
                .GetCustomAttributes<RestrictChildrenAttribute>()
                .FirstOrDefault();
            if (restrictChildrenAttribute == null)
            {
                return null;
            }

            var allowedChildren = restrictChildrenAttribute.ChildTags;
            var validAllowedChildren = GetValidAllowedChildren(allowedChildren, typeInfo.FullName, errorSink);

            if (validAllowedChildren.Any())
            {
                return validAllowedChildren;
            }
            else
            {
                // All allowed children were invalid, return null to indicate that any child is acceptable.
                return null;
            }
        }
开发者ID:huoxudong125,项目名称:Razor,代码行数:23,代码来源:TagHelperDescriptorFactory.cs

示例7: GetDataAttributes

 private static IEnumerable<ParadigmDataAttribute> GetDataAttributes(ITypeInfo type)
 {
     return type.GetCustomAttributes(typeof(ParadigmDataAttribute))
         .Select(x => x.GetInstance<ParadigmDataAttribute>());
 }
开发者ID:fulviogabana,项目名称:xUnit.Paradigms,代码行数:5,代码来源:AttributeExemplarFactory.cs

示例8: GetAttribute

 public static DynamoDBAttribute GetAttribute(ITypeInfo targetTypeInfo)
 {
     if (targetTypeInfo == null) throw new ArgumentNullException("targetTypeInfo");
     object[] attributes = targetTypeInfo.GetCustomAttributes(TypeFactory.GetTypeInfo(typeof(DynamoDBAttribute)), true);
     return GetSingleDDBAttribute(attributes);
 }
开发者ID:rossmas,项目名称:aws-sdk-net,代码行数:6,代码来源:Utils.cs

示例9: Initialize

        void Initialize(ITestCollection testCollection, IAssemblyInfo assembly, ITypeInfo type, IMethodInfo method, IAttributeInfo factAttribute, object[] arguments)
        {
            string displayNameBase = factAttribute.GetNamedArgument<string>("DisplayName") ?? type.Name + "." + method.Name;
            ITypeInfo[] resolvedTypes = null;

            if (arguments != null && method.IsGenericMethodDefinition)
            {
                resolvedTypes = ResolveGenericTypes(method, arguments);
                method = method.MakeGenericMethod(resolvedTypes);
            }

            Assembly = assembly;
            Class = type;
            Method = method;
            Arguments = arguments;
            DisplayName = GetDisplayNameWithArguments(displayNameBase, arguments, resolvedTypes);
            SkipReason = factAttribute.GetNamedArgument<string>("Skip");
            Traits = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
            TestCollection = testCollection;

            foreach (var traitAttribute in Method.GetCustomAttributes(typeof(ITraitAttribute))
                                                 .Concat(Class.GetCustomAttributes(typeof(ITraitAttribute))))
            {
                var discovererAttribute = traitAttribute.GetCustomAttributes(typeof(TraitDiscovererAttribute)).First();
                var discoverer = ExtensibilityPointFactory.GetTraitDiscoverer(discovererAttribute);
                if (discoverer != null)
                    foreach (var keyValuePair in discoverer.GetTraits(traitAttribute))
                        Traits.Add(keyValuePair.Key, keyValuePair.Value);
            }

            uniqueID = new Lazy<string>(GetUniqueID, true);
        }
开发者ID:vkomarovsky-sugarcrm,项目名称:xunit,代码行数:32,代码来源:XunitTestCase.cs


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