user725497
user725497

Reputation: 11

Explain what this mean in C#?

NotifyOfPropertyChange<ObservableCollection<BaseMdmViewModelCollection>>(() => SubItemsViewModels);

Upvotes: 1

Views: 233

Answers (4)

Gilad Levy
Gilad Levy

Reputation: 13

You have a method NotifyOfPropertyChange(Func func), where in your case T1 is BaseMdmViewModelCollection.

SubItemsViewModels is from type ObservableCollection

This is a way to pass any function that returns the collection instead of passing the collection directly.

Cheers,

Gilad

Upvotes: 0

Gregory A Beamer
Gregory A Beamer

Reputation: 17010

In simple terms: When there is a change in the observable collection, return the Sub items view model.

Upvotes: 3

Bala R
Bala R

Reputation: 108937

It's making a call to a generic function with signature

NotifyOfPropertyChange<T>(Func<BaseMdmViewModelCollection>)

() => SubItemsViewModels

is identical to

delegate { return SubItemsViewModels; }

In other words,

NotifyOfPropertyChange<ObservableCollection<BaseMdmViewModelCollection>>(() => SubItemsViewModels);

is the same as

NotifyOfPropertyChange<ObservableCollection<BaseMdmViewModelCollection>>(Foo);

where Foo would be

private BaseMdmViewModelCollection Foo()
{
    return SubItemsViewModels;
}

Upvotes: 3

NateTheGreat
NateTheGreat

Reputation: 2305

I'd be willing to bet that your NotifyOfPropertyChange method is using the Func to simply get the name of the property that changed. This gives you compile-time safety of property changes, which is much more preferable than saying NotifyPropertyChange("SubItemsViewModels"). This approach is used extensively in WPF and Silverlight data bindings, but is also a general purpose pattern that is useful in many scenarios.

Upvotes: 0

Related Questions