C
C#17mo 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
Steak17mo ago
aww, thanks for letting me know. I probably gonna use codeGen. what do you think?
canton7
canton717mo ago
What sort of code gen?
Steak
Steak17mo ago
c# code gen, that generates code, or maybe I should use ILWeaver or mono Cecil
canton7
canton717mo 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
Steak17mo ago
it should be the ILWeaver, the Mono Cecil, It lets replace some code in the compiled assemblies
canton7
canton717mo 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
Steak17mo ago
I want the Weaver to replace the attribute [UnExecuteable] to [Conditional()] shouldn't affect the method or anything
canton7
canton717mo 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
Steak17mo ago
damn, you're right thanks for the talk 😃 👍
Accord
Accord17mo 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.