Jump to content
  • Advertisement
Sign in to follow this  

[.net] Can I enforce a specific method signature using a custom Attribute?

This topic is 2596 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Topic says it all. I'd like to do some stuff with Methods in .NET, but I also require that any method tagged with my custom Attribute also have a specific signature (for instance null MyMethod() - no parameters, no return type.)


I can do this by throwing an exception at runtime, but it would be so much nicer to throw a compile-time error. Is there a way to enforce this at compile-time?

Share this post


Link to post
Share on other sites
Advertisement
As far as I know you cannot use custom attributes to influence compile time behavior. Still this would be awfully nice, I have wanted to do the very same thing on several occasions.

Share this post


Link to post
Share on other sites
I imagine there might be a way to fake this behavior using code templates (use the template to generate no-op/whitespace if good, some compile error on bad). Or a simple post-build task to do the static analysis.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!