Can you convert an attribute to a modifier?

41 views Asked by At

For example, could I make [System.Serializable] into a new modifier so I could type public serializable struct SaveData { ... }

1

There are 1 answers

0
phi1010 On BEST ANSWER

No, not without building your own compiler. Modifiers are defined as keywords in the C# language specification, and can not be changed by the user.

There are some undocumented keywords that are compiler-specific, like __arglist in the Microsoft implementation (see https://www.codeproject.com/Articles/38695/UnCommon-C-keywords-A-Look#arg), but to add your own, you would need to change the compiler source code.

Apart from that, a custom precompiler transforming the files before compilation might help.

Both variants may improve readability, but will definitely make the building process more error-prone, so I would suggest to refrain from this if possible.