I'm writing on a script for Unity 3D and have/want to use some pre-processors.
For example VisualStudio always throughs some warnings such as
Field 'foo' is never assigned to, and will always have its default value 'null' (CS0649) (Assembly-CSharp)
for a code like
puclic class Example : MonoBehvaiour
{
[SerializedField]
private GameObject exampleObject;
...
}
though the field ofcourse will be set within the Inspector of the Unity Editor.
Additionally I never use the field in this class but have written a CustomEditor where the field is needed. So I also would get some other warnings something like
variable declared but not used.
variable assigned but not used.
private field assigned but not used.
So after making sure that the code is correct and those warnings unneccesary I decided to follow this and this post and used some pre-processors e.g.
#pragma warning disable 0414
#pragma warning disable 0649
// some fields here
#pragma warning restore 0414
#pragma warning restore 0649
So now to my question:
And how could I add comments for pre-processors?
It's a pity there is not just something like
#comment "some comment here"
This seems not really intended/thought about but I would really like to do it in order to let my collegues know what the pre-processors are good/used for.
Ofcourse I could just add the comments but they are not intended with the pre-processors but with the normal code as e.g.
// This silences "private field assigned but not used." warnings
#pragma warning disable 0414
// flag to look for unsaved changes
private bool _unsavedChanges = false;
// This re-enables "private field assigned but not used" warnings
#pragma warning restore 0414
this makes it look very cluttered instead of clarify things and the comments don't seem to refer/"belong" to the pre-processors but the normal code instead.
The alternative would be inline comments which for now come closest to it I guess
#pragma warning disable 0414 // This silences "private field assigned but not used." warnings
// flag to look for unsaved changes
private bool _unsavedChanges = false;
#pragma warning restore 0414 // This re-enables "private field assigned but not used" warnings
Note:
I do not want to just disable warnings in general for the file or project!
And these examples are not the only pre-processors I'ld like to add comments for.