5
A
回答
8
我不知道你是否要求t4框架,但這裏是一個反作用過時標記方法的反射樣本。
class TestClass
{
public TestClass()
{
DeprecatedTester.FindDeprecatedMethods(this.GetType());
}
[Obsolete("SomeDeprecatedMethod is deprecated, use SomeNewMethod instead.")]
public void SomeDeprecatedMethod() { }
[Obsolete("YetAnotherDeprecatedMethod is deprecated, use SomeNewMethod instead.")]
public void YetAnotherDeprecatedMethod() { }
public void SomeNewMethod() { }
}
public class DeprecatedTester
{
public static void FindDeprecatedMethods(Type t)
{
MethodInfo[] methodInfos = t.GetMethods();
foreach (MethodInfo methodInfo in methodInfos)
{
object[] attributes = methodInfo.GetCustomAttributes(false);
foreach (ObsoleteAttribute attribute in attributes.OfType<ObsoleteAttribute>())
{
Console.WriteLine("Found deprecated method: {0} [{1}]", methodInfo.Name, attribute.Message);
}
}
}
}
相關問題
- 1. 使用Reflection和LINQ查詢ApplicationDataService
- 2. VB折舊
- 3. 折舊警告當我使用sklearn imputer
- 4. Threejs setHSL()已折舊?
- 5. put_block_blob_from_path折舊了嗎?
- 6. GLEW和OpenGL折舊
- 7. TensorFlow:SKCompat折舊警告
- 8. Facebook:查找舊帖子
- 9. 使用Scala Reflection來實現插件架構
- 10. 使用連接來查找用戶
- 11. Bash腳本來查找並顯示最舊的文件
- 12. Moment.js折舊 - 如何找到導致waring的代碼行?
- 13. Swift 3和AVCaptureDevice折舊,當試圖找到攝像頭名稱
- 14. Silverlight reflection
- 15. 使用雙數組來查找模式?
- 16. 使用查找表來填充多列
- 17. 可以使用IN()來查找INTERSECT
- 18. 使用execvp來實現查找命令
- 19. 使用jQuery來展開/摺疊文本
- 20. 使用Reflection創建靜態對象
- 21. .NET/C# - Reflection - 曾經使用過的System.IO.File
- 22. 使用Reflection獲取父類的名字
- 23. C# - 折半查找(排序)字典
- 24. 如何使用來自舊迴歸
- 25. 使用git來維護舊版本
- 26. 使用Reflection調用使用MethodInfo實例的方法。使用Reflection.Emit
- 27. 在MSMQ中查找舊郵件
- 28. 查找並替換行sed舊版本
- 29. 如何在Confluence中查找'舊'頁面?
- 30. Java Interface Reflection Alternatives
您是否在T4中使用反射?這是[不推薦](http://www.olegsych.com/2007/12/how-to-use-t4-to-generate-decorator-classes/)。 – Ani 2011-02-08 21:36:58
你的意思是標記爲Obsolete的成員(是被動框架的一部分嗎?) – RQDQ 2011-02-08 21:37:31