本文整理汇总了C#中ITypeInfo.HasMethodWithAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeInfo.HasMethodWithAttribute方法的具体用法?C# ITypeInfo.HasMethodWithAttribute怎么用?C# ITypeInfo.HasMethodWithAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeInfo
的用法示例。
在下文中一共展示了ITypeInfo.HasMethodWithAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanBuildFrom
/// <summary>
/// Checks to see if the provided Type is a fixture.
/// To be considered a fixture, it must be a non-abstract
/// class with one or more attributes implementing the
/// IFixtureBuilder interface or one or more methods
/// marked as tests.
/// </summary>
/// <param name="typeInfo">The fixture type to check</param>
/// <returns>True if the fixture can be built, false if not</returns>
public bool CanBuildFrom(ITypeInfo typeInfo)
{
if (typeInfo.IsAbstract && !typeInfo.IsSealed)
return false;
if (typeInfo.IsDefined<IFixtureBuilder>(true))
return true;
// Generics must have an attribute in order to provide
// them with arguments to determine the specific type.
// TODO: What about automatic fixtures? Should there
// be some kind of error shown?
if (typeInfo.IsGenericTypeDefinition)
return false;
return typeInfo.HasMethodWithAttribute(typeof(IImplyFixture));
}
示例2: IsValidFixtureType
private bool IsValidFixtureType(ITypeInfo typeInfo, ref string reason)
{
if (typeInfo.IsAbstract)
{
reason = string.Format("{0} is an abstract class", typeInfo.FullName);
return false;
}
if (!typeInfo.HasConstructor(new Type[0]))
{
reason = string.Format("{0} does not have a default constructor", typeInfo.FullName);
return false;
}
var invalidAttributes = new Type[] {
typeof(SetUpAttribute),
typeof(TearDownAttribute),
#pragma warning disable 618 // Obsolete Attributes
typeof(TestFixtureSetUpAttribute),
typeof(TestFixtureTearDownAttribute) };
#pragma warning restore
foreach (Type invalidType in invalidAttributes)
if (typeInfo.HasMethodWithAttribute(invalidType))
{
reason = invalidType.Name + " attribute not allowed in a SetUpFixture";
return false;
}
return true;
}