Catel.Data.ChangeNotificationWrapper.SubscribeNotifyChangedEvents C# (CSharp) Method

SubscribeNotifyChangedEvents() public method

Subscribes to the notify changed events.
public SubscribeNotifyChangedEvents ( object value, ICollection parentCollection ) : void
value object The object to subscribe to.
parentCollection ICollection If not null, this is a collection item which should use .
return void
        public void SubscribeNotifyChangedEvents(object value, ICollection parentCollection)
        {
            if (value == null)
            {
                return;
            }

            lock (_lockObject)
            {
                var collectionChangedValue = value as INotifyCollectionChanged;
                if (collectionChangedValue != null)
                {
                    SubscribeNotifyChangedEvent(collectionChangedValue, EventChangeType.Collection, parentCollection);

                    var collection = value as ICollection;
                    if (collection != null)
                    {
                        foreach (var child in collection)
                        {
                            SubscribeNotifyChangedEvents(child, collection);
                        }
                    }
                }

                var propertyChangedValue = value as INotifyPropertyChanged;
                if (propertyChangedValue != null)
                {
                    // ObservableObject implements PropertyChanged as protected, make sure we accept that in non-.NET languages such
                    // as Silverlight, Windows Phone and WinRT
                    try
                    {
                        SubscribeNotifyChangedEvent(propertyChangedValue, EventChangeType.Property, parentCollection);
                    }
                    catch (Exception ex)
                    {
                        Log.Warning(ex, "Failed to subscribe to PropertyChanged event, the event is probably not public");
                    }
                }
            }
        }