Method Attributes

image_pdfimage_print
   
 

using System;
using System.Reflection;
public class TransactionableAttribute : Attribute {
    public TransactionableAttribute() {
    }
}

class SomeClass {
    [Transactionable]
    public void Foo() { }

    public void Bar() { }

    [Transactionable]
    public void Goo() { }
}

class Test {
    [STAThread]
    static void Main(string[] args) {
        Type type = Type.GetType("SomeClass");
        foreach (MethodInfo method in type.GetMethods()) {
            foreach (Attribute attr in
                method.GetCustomAttributes(true)) {
                if (attr is TransactionableAttribute) {
                    Console.WriteLine(method.Name);
                }
            }
        }
    }
}