❔ How can i remove methods or classes with an Attribute from compiling?
How can i remove methods or classes with an Attribute from compiling?
30 Replies
ok
what i need todo?
That seems like an XY issue tbh
would it not possible with a attribute
Ah, so trying to fix a fucked up architecture, carry on
is the #if the best way?
would it possible to set the #if variable with c# code
or just with XNA
:/
what is #define doing?
eh i not think they can
i just like the code style more
instead of the #if
Attributes are something you get on runtime during reflection, or on compile time using source generators
You can't arbitrarily exclude code from compilation using them
Since reflections cannot do that
And source generators can only generate code, not delete or overwrite it
So either:
a) rethink your architecture
b) deal with it
man i just find the best way
but yea thx i use the #if thing
if it would work with my system
@Mathf.Lerp i doing a API so i need to allow other users to disable or enable it
and i think you can not overwrite it
Uh, an API is compiled once, and runs on the server
Unless you want the users to be able to recompile it?
And remove arbitrary code?
Which seems, uh, mental
idk would it not possible to doing any generated file that allow you to set the headless variable to true or false
With
#if
you can check for variables in the csprojyea ik
so i need to change it before i compile it
Or just use simple logic where needed
oh wait
if i doing now something like that?
can i define it in a project that refernce this?
https://stackoverflow.com/a/61122781/6042255 ye
Well, uh, kinda
Weird, I thought you can just easily use csproj variables, but it seems like you need
#define
after allif i define that now:
should it not normaly not anymore possbile to call the Input?
Because it still is
mhh i see that would not work
the closes thing to what you're asking is
[Conditional()]
which only works because Roslyn is designed to specifically look for it, and change its behavior accordinglyConditionalAttribute Class (System.Diagnostics)
Indicates to compilers that a method call or attribute should be ignored unless a specified conditional compilation symbol is defined.
other than that, yes, this very much sounds like an XY problem
Does that really remove it from the compiler or just ingore it?
not entirely sure
mhh
kk
but if i want to remove it from the compiler i need to use #if
in some form, yes
and you guys know no other ways
that i can remove it with a attribute
no
there is no such thing
attributes do nothing
ever
if you want things to be excluded from your build, you need to talk to the thing that builds it: the compiler
the compiler's support for excluding things from builds includes that attribute I linked to, and pre-processor directives
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.