❔ Wrapping Conditional Attribute
Is There a way to wrap Conditional attribute, so I wouldn't have to declare Conditional Attribute all over?
❌❌❌
✅✅✅
11 Replies
I suspect no -- the code which looks at that attribute does an exact name match: https://sourceroslyn.io/#Microsoft.CodeAnalysis/Symbols/Attributes/CommonAttributeData.cs,88, called from https://sourceroslyn.io/#Microsoft.CodeAnalysis.CSharp/Symbols/Source/SourceNamedTypeSymbol.cs,936
aww, thanks for letting me know. I probably gonna use codeGen. what do you think?
What sort of code gen?
c# code gen, that generates code, or maybe I should use ILWeaver or mono Cecil
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
it should be the ILWeaver, the Mono Cecil, It lets replace some code in the compiled assemblies
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
I want the Weaver to replace the attribute
[UnExecuteable]
to [Conditional()]
shouldn't affect the method or anythingRight, 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
damn, you're right
thanks for the talk 😃 👍
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.