Esempio n. 1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ViewModel" /> class.
 /// </summary>
 /// <param name="commands">The commands.</param>
 /// <param name="dataItems">The data items.</param>
 public ViewModel(CommandsContainer commands,
                  DataItemsContainer dataItems)
     : this()
 {
     _commands  = commands;
     _dataItems = dataItems;
 }
Esempio n. 2
0
        /// <summary>
        ///     Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing">
        ///     <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.
        /// </param>
        /// <returns>
        ///     <c>true</c> if operation is allowed
        /// </returns>
        protected override bool Dispose(bool disposing)
        {
            if (!disposing)
            {
                return(false);
            }

            Unsubscribe();

            if (_properties != null)
            {
                _properties.Clear();
                _properties = null;
            }

            if (_commands != null)
            {
                _commands.ForEach(pair =>
                {
                    if (pair.Value is IDisposable)
                    {
                        (pair.Value as IDisposable).Dispose();
                    }
                });
                _commands.Clear();
                _commands = null;
            }

            if (_dataItems != null)
            {
                _dataItems.Values.ForEach(item =>
                {
#if UNITY3D
                    if (item is MonoBehaviourBase)
                    {
                        var mono = (item as MonoBehaviourBase);
                        // destroy in case me isn't a child of item
                        if (!transform.IsChildOf(mono.transform))
                        {
                            Destroy(mono);
                        }
                    }
                    else if (item is IDisposable)
                    {
                        var disposable = item as IDisposable;
                        var vm         = disposable as ViewModel;
                        // destroy in case me isn't a child of item
                        if (vm == null || !vm.IsChildOf(this))
                        {
                            disposable.Dispose();
                        }
                    }
#else
                    if (item is IDisposable)
                    {
                        var disposable = item as IDisposable;
                        var vm         = disposable as ViewModel;
                        // destroy in case me isn't a child of item
                        if (vm == null || !vm.IsChildOf(this))
                        {
                            disposable.Dispose();
                        }
                    }
#endif
                    if (item is IList)
                    {
                        (item as IList).Clear();
                    }
                });
                _dataItems.Clear();
                _dataItems = null;
            }

            return(base.Dispose(true));
        }