Example #1
0
        protected ViewModelWrapper(object @object, bool clearOriginalProperties = true)
        {
            Object = @object;

            // Copy Object properties
            var field       = AccessTools2.Field(typeof(ViewModel), "_propertyInfos");
            var propsObject = field?.GetValue(Object) as Dictionary <string, PropertyInfo> ?? new Dictionary <string, PropertyInfo>();
            var propsThis   = field?.GetValue(this) as Dictionary <string, PropertyInfo> ?? new Dictionary <string, PropertyInfo>();

            if (clearOriginalProperties)
            {
                propsThis.Clear(); // clear properties
            }
            foreach (var(key, value) in propsObject)
            {
                propsThis[key] = new WrappedPropertyInfo(value, Object, () =>
                {
                    OnPropertyChangedWithValue(value.GetValue(Object), value.Name);
                    OnPropertyChanged(value.Name);
                });
            }

            // Trigger OnPropertyChanged from Object
            if (Object is INotifyPropertyChanged notifyPropertyChanged)
            {
                notifyPropertyChanged.PropertyChanged += OnPropertyChangedEventHandler;
            }
            if (Object is ViewModel viewModel)
            {
                viewModel.PropertyChangedWithValue += OnPropertyChangedWithValueEventHandler;
            }
        }
        /// <inheritdoc />
        public override bool Equals(object obj)
        {
            var otherExplicitelyMappedPropertyInfo = obj as ExplicitlyMappedPropertyInfo;

            if (otherExplicitelyMappedPropertyInfo == null)
            {
                return(false);
            }

            return(WrappedPropertyInfo.Equals(otherExplicitelyMappedPropertyInfo.WrappedPropertyInfo) &&
                   Predicate.Equals(otherExplicitelyMappedPropertyInfo.Predicate) &&
                   Equals(Graph, otherExplicitelyMappedPropertyInfo.Graph));
        }