如何使用C#使用MsTest对属性进行单元测试?

Jad*_*ias 7 .net c# attributes mstest visual-studio

如何使用C#测试MsTest的类属性和方法属性的存在?

Rob*_*vey 8

C#用于检查属性的扩展方法

public static bool HasAttribute<TAttribute>(this MemberInfo member) 
    where TAttribute : Attribute
{
    var attributes = 
        member.GetCustomAttributes(typeof(TAttribute), true);

    return attributes.Length > 0;
}
Run Code Online (Sandbox Code Playgroud)