✅ Attribute that can remove Methods and class from compiling
Hi, im looking for a attribute that can remove methods and classes from the compiler, or would it possbile to doing something like that by my self?
21 Replies
In what contect?
You can use preprocessors if you for example want something only during debug mode.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#conditional-compilation
i need it for like a attribute
so like
No such attribute
Only conditional preprocessor is the go-to for that.
so you mean the #if
Yes.
there are also partial methods that are removed if not implemented
attibute like contional would cool
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.no
What else are you waiting for?
stephen toub to implement selective methods :p
Is there no way to impliment this?
You got the answer above I believe, conditional preprocessors?
Would IT possible to do a Attribute for it
There's:
https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.conditionalattribute?view=net-7.0
But it only works for
void
methods
So unless that fits the bill for all methods you're trying to exclude, probably easier to just go with the original suggestion
Is there a reason you "need" it to be an attribute?I Just want a Clean system
Because IT get often used
And allot of #if would look at the time very messy and a simple Attribute could clean that
nothing that works for classes and all methods (Functions)
Not that I'm aware of, think you're asking for something that doesn't exist
I've mentioned what exists. Source generators can't rewrite source, only add to it. So that's out of the question.
Conditional Preprocessor is the only way.
You can write an external program that analyzes the code and automatically adds a conditional preprocessor, but that'll be too much work for such little gain.
Just use Conditional preprocessor.
:/
What about decompile it
Thats messy to right
Why? No.
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.