开发者

Explain what this mean in C#?

NotifyOfPropertyChange<ObservableCollection<BaseMdmViewModelCollection>>(() => Sub开发者_开发问答ItemsViewModels);


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;
}


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜