src/NetStandard/Core/Core/src/Reflection/Caching/SingleTypePropertyCache.cs
/// <summary>
/// When calling it, you are about to trigger a change of a property.
/// </summary>
/// <param name="propertyName"></param>
When calling it, you are about to trigger a change of a property.
When calling it you are about to trigger a change of a property .
public void SingleTypePropertyNotifierPropertyChanged(string? propertyName)
        {
            if (propertyName == null) {
                return;
            }
            var propertyMember = SingleTypedPropertiesOwnerType.GetVariableMember(propertyName, VariableMemberDescriptor);
            if (propertyMember == null) {
                return;
            }
            var propertyType = propertyMember.GetVariableType();
            PropertyType typedPropertyValue;
            var propertyValue = propertyMember.GetValue(SingleTypedPropertiesOwner);
            if (propertyComparisonMode == PropertyComparisonMode.ValueType && TrackingPropertyType == propertyType
                || propertyComparisonMode == PropertyComparisonMode.ReferenceType && TrackingPropertyType.IsAssignableFrom(propertyType)) {
                typedPropertyValue = (PropertyType)propertyValue;
            } else {
                return; 
            }
            var isPropertNameTracked = cachedPropertyValues.ContainsKey(propertyName);
            if (!isPropertNameTracked
                && CanHandleDefaultValue
                && PropertyValueEqualityComparer.Equals(typedPropertyValue!, TrackingPropertyDefaultValue!)) {
                return;
            }
            void trackPropertyViaArgs(PropertyCachedEventArgs<PropertyType> args)
            {
                cachedPropertyValues.Add(propertyName, args.PropertyValue!);
                OnPropertyCacheAdded(args);
            }
            void trackProperty(PropertyType uncachedProperty)
            {
                var args = new PropertyCachedEventArgs<PropertyType>(propertyName, uncachedProperty);
                trackPropertyViaArgs(args);
            }
            void untrackProperty(PropertyType cachedProperty, bool isRetrack)
            {
                cachedPropertyValues.Remove(propertyName);
                if (isRetrack && CanSkipPropertyRemovedEventInvocationWhenRetracking) {
                    return;
                }
                var args = new PropertyCacheRemovedEventArgs<PropertyType>(propertyName, cachedProperty);
                OnPropertyCacheRemoved(args);
            }
            void retrackProperty(PropertyType cachedProperty, PropertyType uncachedProperty)
            {
                untrackProperty(cachedProperty, true);
                var args = new PropertyCachedEventArgs<PropertyType>(propertyName, uncachedProperty, cachedProperty);
                trackPropertyViaArgs(args);
            }
            if (!isPropertNameTracked) {
                var args = new PropertyCachingEventArgs<PropertyType>(propertyName, typedPropertyValue);
                OnPropertyCacheAdding(args);
                if (!args.CanTrackProperty) {
                    return;
                }
                trackProperty(typedPropertyValue!);
            } else {
                var cachedProperty = cachedPropertyValues[propertyName];
                if (CanHandleDefaultValue && PropertyValueEqualityComparer.Equals(typedPropertyValue!, TrackingPropertyDefaultValue!)) {
                    untrackProperty(cachedProperty, false);
                } else if (!PropertyValueEqualityComparer.Equals(typedPropertyValue!, cachedProperty)) {
                    retrackProperty(cachedProperty, typedPropertyValue!);
                } else {
                    return;
                }
            }
        }
public void SingleTypePropertyNotifierPropertyChanged ( string ? propertyName ) { if ( propertyName == null ) { return ; } var propertyMember = SingleTypedPropertiesOwnerType . GetVariableMember ( propertyName , VariableMemberDescriptor ) ; if ( propertyMember == null ) { return ; } var propertyType = propertyMember . GetVariableType ( ) ; PropertyType typedPropertyValue ; var propertyValue = propertyMember . GetValue ( SingleTypedPropertiesOwner ) ; if ( propertyComparisonMode == PropertyComparisonMode . ValueType && TrackingPropertyType == propertyType || propertyComparisonMode == PropertyComparisonMode . ReferenceType && TrackingPropertyType . IsAssignableFrom ( propertyType ) ) { typedPropertyValue = ( PropertyType ) propertyValue ; } else { return ; } var isPropertNameTracked = cachedPropertyValues . ContainsKey ( propertyName ) ; if ( ! isPropertNameTracked && CanHandleDefaultValue && PropertyValueEqualityComparer . Equals ( typedPropertyValue ! , TrackingPropertyDefaultValue ! ) ) { return ; } void trackPropertyViaArgs ( PropertyCachedEventArgs < PropertyType > args ) { cachedPropertyValues . Add ( propertyName , args . PropertyValue ! ) ; OnPropertyCacheAdded ( args ) ; } void trackProperty ( PropertyType uncachedProperty ) { var args = new PropertyCachedEventArgs < PropertyType > ( propertyName , uncachedProperty ) ; trackPropertyViaArgs ( args ) ; } void untrackProperty ( PropertyType cachedProperty , bool isRetrack ) { cachedPropertyValues . Remove ( propertyName ) ; if ( isRetrack && CanSkipPropertyRemovedEventInvocationWhenRetracking ) { return ; } var args = new PropertyCacheRemovedEventArgs < PropertyType > ( propertyName , cachedProperty ) ; OnPropertyCacheRemoved ( args ) ; } void retrackProperty ( PropertyType cachedProperty , PropertyType uncachedProperty ) { untrackProperty ( cachedProperty , true ) ; var args = new PropertyCachedEventArgs < PropertyType > ( propertyName , uncachedProperty , cachedProperty ) ; trackPropertyViaArgs ( args ) ; } if ( ! isPropertNameTracked ) { var args = new PropertyCachingEventArgs < PropertyType > ( propertyName , typedPropertyValue ) ; OnPropertyCacheAdding ( args ) ; if ( ! args . CanTrackProperty ) { return ; } trackProperty ( typedPropertyValue ! ) ; } else { var cachedProperty = cachedPropertyValues [ propertyName ] ; if ( CanHandleDefaultValue && PropertyValueEqualityComparer . Equals ( typedPropertyValue ! , TrackingPropertyDefaultValue ! ) ) { untrackProperty ( cachedProperty , false ) ; } else if ( ! PropertyValueEqualityComparer . Equals ( typedPropertyValue ! , cachedProperty ) ) { retrackProperty ( cachedProperty , typedPropertyValue ! ) ; } else { return ; } } }
When calling it, you are about to trigger a change of a property.
When calling it you are about to trigger a change of a property .
// There is no member that can be handled, so we return. // We want to assign property value (object) to typed property value.  // The type of the property does not meet the requirements, so we skip the property // We want to abort if tracking property name is untracked and tracking property value is equals default/null. // Add new subscription // Both values are equal, so we don't need to uncache
propertyName
string?
None