ViewModel with auto created properties

Aug 29, 2011 at 7:05 AM

Why not have a viewmodel where you pass an object, and have the viewmodel auto-create its dynamic properties ?

Sep 1, 2011 at 12:39 PM

That is a great idea, would be useful for when you want to pass a model object to an ItemsSource, but need to add a few things.

Could also work like this:

dynamic viewModel = new ViewModel(new { MyProp1 = 0, MyProp2 = 1 });
viewModel.MyProp3 = 2;  //We're adding a property here

Or you could also pass in a regular C# object, or if it came from a database, etc.

I'll see what it takes to get this in there, I think it could be done with dynamic pretty easily.

Sep 5, 2011 at 2:14 PM

This is now feature is now included in NoMvvm if you checkout the source.

It does perform some reflection, but it will be pretty fast if performed on another ViewModel, ExpandoObject, or DynamicObject.

I could also improved performance when the constructor is called over and over by caching call sites, which I will add before next release 1.0.3.  I want to add a few other features also.