Proposal: conditional compilation symbols/pre-processor: allow additional operators #3254
Replies: 6 comments
-
In the early days of .NET, I remember reading blog posts about why the C# preprocessor was quite deliberately simplistic - but I couldn't find them with a quick search.
This wouldn't work. Version 2019.11 is more recent than version 2019.8, but a floating point comparison would get them the wrong way around. |
Beta Was this translation helpful? Give feedback.
-
Version could be zero padded on the minor and patch, like 201900030036. Would need to use a long but that’s ok |
Beta Was this translation helpful? Give feedback.
-
Zero padded out how many zeros? The limitations on preprocessor directives was intentional here. It may be interesting to see if being limited to symbols has been annoying for the CoreFX team. |
Beta Was this translation helpful? Give feedback.
-
That’s why I mentioned using a long. I updated the proposal example with something that is cleaner. |
Beta Was this translation helpful? Give feedback.
-
If this was a major ecosystem ask, i think it could be done. However, touching this corner of the language for something not common is pretty unlikely to happen. |
Beta Was this translation helpful? Give feedback.
-
Perhaps it is a niche feature, more data would need to be gathered. I am hopeful it would be a fairly simple tweak to the C# pre-processor logic, but I could be wrong. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This would allow >=, <=, < and >. Preprocessor value would be converted to long or double if needed. Would be helpful comparing versions or other values that are not a simple true/false.
Use case: Unity engine defines preprocessor such as 2019_3_OR_NEWER, and does for each version of the editor. I’m sure there are many other use cases as well.
Example of new feature:
In project conditional compilation symbols:
UNITY_VERSION_MAJOR=2019; UNITY_VERSION_MINOR=3; UNITY_VERSION_PATCH=36
Code:
If this has been suggested before feel free to close otherwise I can tidy it up to match the feature suggestion template.
Beta Was this translation helpful? Give feedback.
All reactions