-
Notifications
You must be signed in to change notification settings - Fork 97
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 for custom primitive types #1498
Conversation
Awesome, this is the subject of #809. We will have to leave it for 5.0, since this breaks quite many things. Or maybe put it behind a feature flag. |
src/Framework/Framework/Configuration/DotvvmRuntimeConfiguration.cs
Outdated
Show resolved
Hide resolved
src/Framework/Framework/Resources/Scripts/validation/validation.ts
Outdated
Show resolved
Hide resolved
src/Samples/Common/ViewModels/FeatureSamples/CustomPrimitiveTypes/SampleId.cs
Show resolved
Hide resolved
public class CustomPrimitiveTypeAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Gets a type which will be used for this custom type on the client side. Only types from ReflectionUtils.PrimitiveTypes (or their nullable versions) are supported. |
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 type can not be actually nullable. We handle those differently
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.
What is the problem with nullable types here? In the sample, we are using Guid?
since the typed id is a reference type and can be null.
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 use-case seems to work nicely with reference types. If SampleId
, which is a reference type, maps to Guid?
- then properties that are of type SampleId
work correctly.
The problem comes when SampleId
is a value type (struct). Then we can have also a nullable and non-nullable property. This can generate funny stuff like 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.
We should probably add a check when generating metadata for value types so that such situation can not happen. Otherwise users should not registrate these with nullable underlying type, otherwise it can be doubled.
@@ -17,11 +17,15 @@ public class DotvvmExperimentalFeaturesConfiguration | |||
[JsonProperty("explicitAssemblyLoading")] | |||
public DotvvmGlobalFeatureFlag ExplicitAssemblyLoading { get; private set; } = new DotvvmGlobalFeatureFlag(); | |||
|
|||
[JsonProperty("useDotvvmSerializationForStaticCommandArguments")] | |||
public DotvvmGlobalFeatureFlag UseDotvvmSerializationForStaticCommandArguments { get; private set; } = new DotvvmGlobalFeatureFlag(); |
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.
Rename to UseDotvvmSerializationForStaticCommands
Add XML comment
Will be true by default in the next release
Make sure it applies also for static command response
We just discussed with @exyi that there is another potential issue - when user creates a custom primitive type and binds it into a textbox. How to treat this expression?
I am not sure that this behaviour is clear or generally expected by users. What is the correct approach here? |
Furthermore, format overriding is not trivial (see our textbox binding handler 😄). The easiest solution would be IMO to format based on the underlying type |
|
f3385e2
to
48119e0
Compare
One more small issue - Currently, the validator skips all primitive types. I'd expect it to be validated if the custom primitive implements |
696a647
to
876d386
Compare
CustomPrimitiveTypes collection changed to private
…iganti/dotvvm into feature/custom-primitive-types
The last thing we wanted to do is to change the |
This allows for efficient checks if a value is primitive without the need for cache hashtable containing all types we encounter
…interface Switch custom primitive types to a marker interface
We've added support for registering custom primitive types.
There is one unresolved issue - the static command wasn't deserializing method arguments using converters from DotVVM.
We've introduced this, but:
DotvvmPresenter
that should not depend onNewtonsoft.Json
. I think it should be moved toIViewModelSerializer
, or maybe added as another interface.Also, unit tests and UI tests are missing.