-
Notifications
You must be signed in to change notification settings - Fork 164
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
Dynamic Properties won't work because of Json.Net #53
Comments
Hi, what's your use case for having dynamic properties in a view model? I'm afraid I have even less stackoverflow reputation; @tw-bert, can you help? |
Sure, tag is added. |
@dsuryd Writing out the properties and different viewmodels that don't contain any or just minor extra logic often feels really dumb and repetitive for me. Thats why I have this in my ViewModel Base Class:
and some other variants of it. Example:
|
I have progress on this. Thanks to dbc at Stackoverflow I could implement a TypeDescritorContractResolver that does the serialization now without my workaround. While I think my special problem has low priority for dotnetify, I still think that dotnetify should approach the same resolution strategy and possibilities with properties like WPF. I will update the fork soon. |
@KeilFelix : I wouldn't say this problem is so special. At our company (not related to dotnetify at all, but starting to use it, since it's great) we use dynamic properties and Expando objects and the likes as well, and we would benefit a lot from this addition. Thank you for your input! |
The stackoverlow solution looks good! Is there a way to check beforehand whether an object is imbued with TypeDescriptor properties, in order to apply the appropriate contract resolver? |
The latest in master branch has full Rx support, including dynamic properties and view model types. Example with dynamic type + properties: VMController.Register("HelloWorldVM", _ =>
{
var vm = new BaseVM();
var firstName = vm.AddProperty("FirstName", "Hello");
var lastName = vm.AddProperty("LastName", "World");
vm.AddProperty<string>("FullName").SubscribeTo(
Observable.CombineLatest(firstName, lastName, (fn, ln) => $"{fn} {ln}"));
return vm;
}); Example without BaseVM: public class HelloWorldVM : INotifyPropertyChanged, IReactiveProperties
{
public event PropertyChangedEventHandler PropertyChanged = delegate { };
public IList<IReactiveProperty> RuntimeProperties { get; } = new List<IReactiveProperty>();
public HelloWorldVM()
{
var firstName = this.AddProperty("FirstName", "Hello");
var lastName = this.AddProperty("LastName", "World");
this.AddProperty<string>("FullName").SubscribeTo(
Observable.CombineLatest(firstName, lastName, (fn, ln) => $"{fn} {ln}"));
}
} I don't use TypeDescriptor,and don't see the need for dotNetify to support its serialization, now that the motivation for it has been realized through other means. But if you still want to use it, you can implement your own view model serializer. |
This looks really great! I think that this issue can be closed. The BaseVm class has really improved. Very good idea with the wrapper constructor too! Kudos |
I use dynamic Properties in my ViewModels.
See this for further info:
http://putridparrot.com/blog/dynamically-extending-an-objects-properties-using-typedescriptor/
These prop work well in WPF but get lost in the JSON Serializer.
I have a temporary workaround in fork and I am currently trying to find a better solution.
https://stackoverflow.com/questions/46888732/how-to-serialize-runtime-added-properties-to-json
Btw. there is no dotnetify tag on stackoverflow yet and I couldn't add it with <1500 rep. Maybe you can add it?
PS: dotnetify is awesome! Thank you!
The text was updated successfully, but these errors were encountered: