December 16, 2009

Sample Custom Method Attribute.

An example of a custom attribute on a method:
[AttributeUsage(AttributeTargets.Method)] 
public class ProjectReloadRequiredAfterTestAttribute
 : System.Attribute
{
}

public void Discover(MethodBase mb)
{
  if (mb.GetCustomAttributes(typeof(
      ProjectReloadRequiredAfterTestAttribute), 
      false).Length > 0)
  {
    reloadProjectRequired = true;
  }
}  
 
[Test]
[ProjectReloadRequiredAfterTestAttribute]
public void TestCreateAndDeletePart()
{
  Discover(System.Reflection.MethodBase.GetCurrentMethod());
  ...
}

No comments: