最近、C#プロジェクトを.NET3.5から.NET4にアップグレードしました。指定されたMethodBase
インスタンスのリストからすべてのMSTestテストメソッドを抽出するメソッドがあります。その体は次のようになります。
return null == methods || methods.Count() == 0
? null
: from method in methods
let testAttribute = Attribute.GetCustomAttribute(method,
typeof(TestMethodAttribute))
where null != testAttribute
select method;
これは.NET3.5で機能しましたが、プロジェクトを.NET 4にアップグレードしてから、。でマークされたメソッドを含むメソッドのリストが指定された場合でも、このコードは常に空のリストを返します[TestMethod]
。.NET 4のカスタム属性で何か変更がありましたか?
デバッグの結果GetCustomAttributesData()
、テストメソッドの結果から、 CustomAttributeData
VisualStudio2010の[ローカル]ウィンドウに次のように記述されている2つのリストが表示されることがわかりました。
Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute("myDLL.dll")
Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()
-これが私が探しているものです
GetType()
ただし、その2番目CustomAttributeData
のインスタンスを呼び出すと、が取得され{Name = "CustomAttributeData" FullName = "System.Reflection.CustomAttributeData"} System.Type {System.RuntimeType}
ます。のリストからテストメソッドを抽出できるように、TestMethodAttribute
どうすればから抜け出すことができますか?CustomAttributeData
MethodBase