#Custom [Preserve] attribute

1 messages · Page 1 of 1 (latest)

pseudo crypt
#

I want to make it so that specific attributes of mine automaticaly apply Preserve to all of their targets, and also marks the code as used for Visual Studio, to prevent gray-out.
It would be even better if I can make any attribute behave this way by adding another attribute (like [PreserveTargets]) to their declarations.

#

Example:

[PreserveAttributeTargets]
public class RunOnGameInitializationAttribute : Attribute { }```
split anchor
#

for the IDE usages, i'm pretty sure MeansImplicitUse is what you need, it's one of the Jetbrains annotations included with Unity

#

according to the docs you can define your own preserve attribute too, but it has to be named PreserveAttribute so i guess you're out of luck if you want a nicer name

pseudo crypt
#

Thanks for the anwser. Sadly MeansImplicitUse only works with jetbrains and not with Visual Studio. I found a possible solution in the meantime though: It seams that the preserve part might be possible with an ILPostProcessor, which basicaly appends the code with Unity's Preserve attribute when compiled, but I don't realy know how to do it yet.

split anchor
#

ah, it's been many years since i've touched VS without resharper installed 😄