Tôi không biết liệu bạn có yêu cầu khung t4 hay không nhưng đây là mẫu phản chiếu chung cho các phương pháp bị gắn cờ cũ.
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);
}
}
}
}
Bạn đang sử dụng phản chiếu với T4? Đây là [không khuyến khích] (http://www.olegsych.com/2007/12/how-to-use-t4-to-generate-decorator-classes/). – Ani
Bạn có nghĩa là các thành viên được đánh dấu là lỗi thời (là một phần của khung phản ứng?) – RQDQ
Sửa đổi một mẫu T4 để tạo ra các quan sát trong các đại biểu giao diện người dùng và nó sẽ nhận các sự kiện không được chấp nhận, tôi chỉ cần lọc chúng ra lúc tạo. –