using System;
namespace MethodAttribs
{
public class TransactionableAttribute:Attribute
{
public TransactionableAttribute()
{}
}
/// <summary>
/// SomeClass 的摘要说明。
/// </summary>
///
class SomeClass
{
[Transactionable]
public void Foo()
{}
public void Bar()
{}
[Transactionable]
public void Goo()
{}
}
class Test
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
Type type=Type.GetType("MethodAttribs.SomeClass");
foreach(MethodInfo method in type.GetMethods())
{
foreach(Attribute attr in method.GetCustomAttributes(true))
{
if(attr is TransactionableAttrubute)
{
Console.WriteLine("{0} is transactionable.",method.Name);
}
}
}
}
}
}
<c#精髓>上的代码又出现问题,很有挫折感,MethodInfo以及Method类都没有给出....
感觉代码挺精妙的,但是实现不了,郁闷..................