-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support TimeSpan type in the RangeAttribute emitted code by options validation source generator #94119
Comments
Tagging subscribers to this area: @dotnet/area-extensions-options Issue DetailsThe RangeAttribute employs a TypeConverter, which renders it incompatible with AOT compilation. The Options source generator identifies the usage of the RangeAttribute and generates strongly typed attribute code. The generator currently supports this only for a predefined list of basic types, as indicated here: link. TimeSpan is not included in the supported list, despite its use in real application scenarios. This issue is being tracked to add support for TimeSpan and possibly other types like DateTimeOffset.
|
|
Why do you think this is a problem? The behavior is well defined, and users have control on the values they can use in the range attribute. |
Principle of least surprise problems. The behavior is well defined, sure, but that assumes that the people doing the configuration know that whatever application has been written in C#, and that the element type follows the given behavior. |
The change here is not going to add or introduce any behavior change. The |
I believe this could be addressed in part using the API as originally proposed here: #82526. API review at the time indicated that we should focus on shipping a new generic range type instead, but wondering if this scenario is sufficient to reconsider. cc @jeffhandley |
@eiriktsarpalis this will help except of users already using the constructor |
Given that this constructor only works with a small number of known types, it is conceivable that the source generator could intercept it, parse the type symbol and strings at compile time, replacing it with a call to the proposed |
This is not going to help in anything for this case because we must convert the string values to the object type (like TimeSpan in this case). The whole issue we are trying to handle here is avoid using type converter. This is why the source generator handles a limited set of types. Another side question, can the C# attribute accept interface types in the constructors as the proposal has? This is interesting to me. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/attributes#2224-attribute-parameter-types |
oh, I see now the proposal is changed to have a generic type attribute. that make sense now :-) |
I think it should be possible to have it work for the case of the non-generic variant as well. |
I added my thoughts to that proposal: #82526 (comment). If we went with something like that, we wouldn't need to change the source gen at all. |
The RangeAttribute employs a TypeConverter, which renders it incompatible with AOT compilation. The Options source generator identifies the usage of the RangeAttribute and generates strongly typed attribute code. The generator currently supports this only for a predefined list of basic types, as indicated here: link.
TimeSpan is not included in the supported list, despite its use in real application scenarios. This issue is being tracked to add support for TimeSpan and possibly other types like DateTimeOffset.
The text was updated successfully, but these errors were encountered: