How to generate a compiler error based on an attribute being missing in C#?

Posted by RodH257 on Stack Overflow See other posts from Stack Overflow or by RodH257
Published on 2010-05-06T01:13:27Z Indexed on 2010/05/06 1:18 UTC
Read the original article Hit count: 316

Filed under:
|
|

I create a number of add-ins for the Revit Structure API. Each tool has to habe a class which implements the interface IExternalCommand.

In the latest version of Revit, for your tool to work you need to have two attributes on the class that implements that interface:

[Regeneration(RegenerationOption.Manual)] [Transaction(TransactionMode.Automatic)]

The values in brackets can change, but there must be something there. Often I am finding myself forgetting to put the attributes on, then when it comes to runtime it crashes. Is there any way in Visual Studio 2010 to add a compiler warning or error saying that if your class implements that interface it must have those 2 attributes? I have resharper if that helps.

Can anyone point me into the right direction?

© Stack Overflow or respective owner

Related posts about c#

Related posts about compiler