C
C#10mo ago
MrScautHD

✅ 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
Buddy
Buddy10mo ago
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
MrScautHD
MrScautHD10mo ago
i need it for like a attribute so like
[Headless(true)] .... (Method get removed)
[Headless(true)] .... (Method get removed)
Buddy
Buddy10mo ago
No such attribute Only conditional preprocessor is the go-to for that.
MrScautHD
MrScautHD10mo ago
so you mean the #if
Buddy
Buddy10mo ago
Yes.
WEIRD FLEX
WEIRD FLEX10mo ago
there are also partial methods that are removed if not implemented
MrScautHD
MrScautHD10mo ago
attibute like contional would cool
Accord
Accord10mo 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.
MrScautHD
MrScautHD10mo ago
no
SinFluxx
SinFluxx10mo ago
What else are you waiting for?
WEIRD FLEX
WEIRD FLEX10mo ago
stephen toub to implement selective methods :p
MrScautHD
MrScautHD10mo ago
Is there no way to impliment this?
SinFluxx
SinFluxx10mo ago
You got the answer above I believe, conditional preprocessors?
MrScautHD
MrScautHD10mo ago
Would IT possible to do a Attribute for it
SinFluxx
SinFluxx10mo ago
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?
MrScautHD
MrScautHD10mo ago
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)
SinFluxx
SinFluxx10mo ago
Not that I'm aware of, think you're asking for something that doesn't exist
Buddy
Buddy10mo ago
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.
MrScautHD
MrScautHD9mo ago
:/ What about decompile it Thats messy to right
Buddy
Buddy9mo ago
Why? No.
Accord
Accord9mo 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
More Posts
❔ How to implement integration test asp.net with .net 7 using client certificates ?When i try to create an httpclient custom in a WebApplicationFactory, the test server is not runnin✅ How to use secret manager asp.netGood morning, was wondering how I can import a secret into a C# file using the secret manager. I ini❔ Problem with DS4 Windows setup and .NETHey, i may be wrong here. If so, just delete this. I am trying to install .NET on my pc to run ds4 W❔ Runtime reflection on Asp .net core 7.0 missingHi, I am writing a generator which is used to generated api endpoints in a highly unified way. For t✅ Error in login form c# codeI'm larning C# and WinForms right now and I tried to make a login form. I've seen many people use th❔ Need help with deciding a server and apiSo for my friend and I's desktop messaging app project (WPF .NET framwork), we need a way to store t✅ Easier way to "mark" a class as a different "type" without having to create a new class?Sorry about the title, I'm not sure of the correct terminology Here's my scenario I have a basic c✅ getting app to check repo for latest release, updating if versions don't matchI've created a help channel for this before, but at this point I'm lost. I'm wanting to set my app u❔ Help with creating quad as a vertex listI don't how to make a proper face.❔ Bind derived class and base class to CollectionView and PickerI am trying to bind a derived class to a Picker, and the base class to a CollectionView. Should this