views:

64

answers:

1

I have a bunch of custom attributes in my .NET application and I would like to require the user fills out certain properties within the attribute at runtime. Is this possible?

Ideally I'd like Visual Studio to produce an error when they try to build which states that since they used a particular attribute they must complete X, Y, Z properties of that attribute.

+7  A: 

If you want to force a property to be set then only define constructors on the attribute which take fields corresponding to those properties. This will force the values to be passed at usage time and you can assign them to the property inside the constructor.

JaredPar
Thanks Jared, this is exactly what I needed!
Craig Bovis