I'm trying to understand how the Assem开发者_StackOverflow社区blyVersionAttribute
validates the string format at compile time. I would like to implement something similar in my application (if possible).
For example this is fine :
[assembly: AssemblyVersion("1.0.0.1")]
But this one will cause a compiler error (because the format is invalid) :
[assembly: AssemblyVersion("1a.0.0.1")]
How can I validate a custom attribute in the same way?
IIRC It's the compiler which has this functionality built-in and treats the AssemblyVersion
attribute as special as it has to use its value and bake it into the resulting assembly. Unless writing your own compiler I doubt you could do this with custom attributes. IIRC the best you could do is to restrict the custom attribute target: whether it applies to classes, methods, properties, ... only.
If you decided to implement by Regular Expression
try this regex:
\[assembly: AssemblyVersion\(\"([0-9]{1,}(\.){1}){3}([0-9]{1,}){1}\"\)\]
精彩评论