本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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;
}
示例5: GetValidHtmlTargetElementAttributes
private static IEnumerable<HtmlTargetElementAttribute> GetValidHtmlTargetElementAttributes(
ITypeInfo typeInfo,
ErrorSink errorSink)
{
var targetElementAttributes = typeInfo.GetCustomAttributes<HtmlTargetElementAttribute>();
return targetElementAttributes.Where(
attribute => ValidHtmlTargetElementAttributeNames(attribute, errorSink));
}
示例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;
}
}
示例7: GetDataAttributes
private static IEnumerable<ParadigmDataAttribute> GetDataAttributes(ITypeInfo type)
{
return type.GetCustomAttributes(typeof(ParadigmDataAttribute))
.Select(x => x.GetInstance<ParadigmDataAttribute>());
}
示例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);
}
示例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);
}