C
C#2y ago
Steak

❔ Wrapping Conditional Attribute

Is There a way to wrap Conditional attribute, so I wouldn't have to declare Conditional Attribute all over?
[Conditional("RELEASE")]
[AttributeUsage(AttributeTargets.Method)]
public class UnExecuteableAttribute : Attribute { }
[Conditional("RELEASE")]
[AttributeUsage(AttributeTargets.Method)]
public class UnExecuteableAttribute : Attribute { }
❌❌❌
[Conditional("CLIENT")]
private void Execute() { }
[Conditional("CLIENT")]
private void Execute() { }
✅✅✅
[UnExecuteable]
private void Execute() { }
[UnExecuteable]
private void Execute() { }
11 Replies
Steak
SteakOP2y ago
aww, thanks for letting me know. I probably gonna use codeGen. what do you think?
canton7
canton72y ago
What sort of code gen?
Steak
SteakOP2y ago
c# code gen, that generates code, or maybe I should use ILWeaver or mono Cecil
canton7
canton72y ago
I'm just wondering what sort of code gen could help here I'd just be explicit. Makes the code easier to read and maintain
Steak
SteakOP2y ago
it should be the ILWeaver, the Mono Cecil, It lets replace some code in the compiled assemblies
canton7
canton72y ago
Eh, remember that Conditional causes the compiler to remove those methods at compile time, but weavers work after the compiler has run So your weaver would have to do the job of actually removing the methods (and any calls to those methods, from any assemblies, etc). It wouldn't be be able to just add an attribute
Steak
SteakOP2y ago
I want the Weaver to replace the attribute [UnExecuteable] to [Conditional()] shouldn't affect the method or anything
canton7
canton72y ago
Right, but the Conditional it inserted would have no effect! The method would still be called, always Conditional causes the *compiler * to remove all calls to that method, at compile-time If you're doing things after compile-time, well, it's too late as the compiler has already added the calls to that method
Steak
SteakOP2y ago
damn, you're right thanks for the talk 😃 👍
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server