我正在尝试创建一个单元测试,它只会对那些不抑制相应消息的类型失败。但是,我无法在单元测试中访问我的任何类型的SuppressMessage属性。可以在运行时访问SuppressMessage属性吗?我已经包含了我的单元测试的简化版本。
[System.Diagnostics.CodeAnalysis.SuppressMessage("Foo", "Bar")]
public interface IMyInterface { }
public void UnitTest()
{
var getCustomAttributes = typeof(IMyInterface).GetCustomAttributes(); //Returns an empty array
//Skip check if message should be suppressed
}发布于 2013-11-25 17:28:05
使用条件符号IMyInterface构建程序集(其中定义了CODE_ANALYSIS )
[Conditional("CODE_ANALYSIS")]
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
public sealed class SuppressMessageAttribute : Attribute {https://stackoverflow.com/questions/20199119
复制相似问题