-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Implement more conversions from JsonDynamicValue #15816
Conversation
…mmonly used runtime types.
WalkthroughThe updates focus on enhancing the JSON dynamic handling and content management in OrchardCore. Key improvements include streamlined property accessors in JSON dynamic classes, implementation of the IConvertible interface for better type conversions, and the introduction of new testing methods for robust validation of data types. Additionally, the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Out of diff range and nitpick comments (1)
src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentElement.cs (1)
16-16
: Add XML documentation for the_data
field to maintain consistency with other private fields and enhance code readability.
src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentElement.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Out of diff range and nitpick comments (1)
src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs (1)
237-252
: The methodBindConvert
inJsonDynamicMetaObject
uses reflection to find the appropriate conversion method. Ensure this does not impact performance negatively, especially in high-load scenarios.
src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM.
@sebastienros can you please have a look at this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs
Outdated
Show resolved
Hide resolved
I fixed an regression of this PR, because overloads of |
src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs
Outdated
Show resolved
Hide resolved
@gvkries can you please address @sebastienros and I'll merge this PR. |
@sebastienros you good with the latest changes in this PR? Can we merge it? |
src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs
Outdated
Show resolved
Hide resolved
{ | ||
_value = JsonValue?.GetObjectValue(); | ||
_hasValue = true; | ||
var convertExpression = Expression.Convert(Expression.Convert(Expression, typeof(JsonDynamicValue)), targetType, castMethod); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this expression be cached instead since it varies only by type?
If so you can move the cache initialization code in a static constructor or it might involve unreadable code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gvkries are you able to address the last comment so we can merge this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These expressions are wrapping another expression from the instance property Expression
. We cannot cache them here.
@MikeAlhayek saw that the cached methods were never used while debugging and fixed the issue. I get the point with the Expression. Also reformatted the methods with bodies because I could not read it while working on it locally (to the point that I was confusing the ctor with a property accessor). |
@gvkries what is the point of |
I found a regression because formattable Therefore I think we should keep it. |
Yep sorry. I introduced that bug in the last commit I did 😒 Can we please have a decision when to use expressions vs bodies? It's a total mess and everyone reviewing PRs here has a different opinion... |
@sebastienros typically we use expression-bodies method when there is a single line of code. In this case, these are would be expression-bodied methods. |
My feedback: From this experience I believe that it shouldn't be the complete rule. I'd prefer something like "if the whole thing, method/property declaration "plus" implementation fits in a single line of code (< N char)." If the goal is readability, then I swear it's doing the opposite in these cases. It's still going on a new line, but now you see a bunch of line where before you have braces to delimit the declaration from the body. And I had issues determining it was a method, or even in the case I mentioned a constructor. |
No strong opinion here beside that seems to be the rule we follow. Maybe we should suggest against the use of bodied expressions for methods? This way we can follow a simple rule across the board. |
I second that and if you don't mind, let me add one additional exception: Keep files consistent. E.g. when adding new methods either stick to the existing style or at least change the whole file (I would rather keep the existing format when making functional changes). |
@sebastienros Just to make sure, you still don't want the |
So the dynamic wrapper in Newtonsoft has a similar Honestly a text field has a It might not hurt but once we start adding known/documented things it's hard to remove it so that's why I often try to push hard on not adding seemingly harmless things. I didn't understand the case that would not work without |
Yes, Newtonsoft has this |
I checked the code base for .Value in a cshtml (where I assume it would be used) and only found the properties named |
Reintroduces conversions to fundamental runtime types that were previously supported by
Newtonsoft.Json
but became unavailable following the upgrade toSystem.Text.Json
. By incorporating these conversions, we restore the ability to handle dynamic types effectively, maintaining a seamless transition and compatibility across different JSON processing scenarios.Fixes #15762