Repository: dotnet/efcore
File: src/EFCore/ChangeTracking/Internal/ArrayPropertyValues.cs (C#)

Code before:
            for (var i = 0; i < properties.Count; i++)
            {
                var property = properties[i];
                
                // Skip properties declared in null complex types
                if (IsContainingComplexPropertyNull(property, complexObject))
                {
                    values[i] = null;
                }
                else
                {
                    var getter = property.GetGetter();
                    values[i] = getter.GetClrValue(complexObject);
                }
            }

            // Compute null flags for nullable complex properties
            bool[]? flags = null;
            var nullableComplexProperties = new List<IComplexProperty>();
            foreach (var cp in complexType.GetFlattenedComplexProperties())
            {
                if (!cp.IsCollection && cp.IsNullable && !cp.IsShadowProperty())
                {
                    nullableComplexProperties.Add(cp);
                }
            }

            if (nullableComplexProperties.Count > 0)
            {
                flags = new bool[nullableComplexProperties.Count];

                for (var i = 0; i < nullableComplexProperties.Count; i++)
                {
                    var cp = nullableComplexProperties[i];
                    
                    // Skip if this property is nested within a complex type that's already null
                    if (IsContainingComplexPropertyNull(cp, complexObject))
                    {
                        continue;
                    }
                    
                    flags[i] = cp.GetGetter().GetClrValue(complexObject) == null;
                }
            }

            var complexPropertyValues = new ArrayPropertyValues(entry, values, flags);

            foreach (var nestedComplexProperty in complexPropertyValues.ComplexCollectionProperties)
            {
                var nestedCollection = (IList?)nestedComplexProperty.GetGetter().GetClrValue(complexObject);
                var propertyValuesList = GetComplexCollectionPropertyValues(nestedComplexProperty, nestedCollection);

Review comment (suggestion):
@copilot Use the existing `NullableComplexProperties` property

Code after:
        {
            return null;
        }

        var propertyValuesList = new List<ArrayPropertyValues?>();
        for (var i = 0; i < collection.Count; i++)
        {
            var item = collection[i];
            if (item == null)
            {
                propertyValuesList.Add(null);
            }
            else
            {
                var complexPropertyValues = CreateComplexPropertyValues(
                    item,
                    new InternalComplexEntry((IRuntimeComplexType)complexProperty.ComplexType, InternalEntry, i));
                propertyValuesList.Add(complexPropertyValues);
            }
        }

        return propertyValuesList;

        ArrayPropertyValues CreateComplexPropertyValues(object complexObject, InternalComplexEntry entry)
        {
            var complexType = entry.StructuralType;
            var properties = complexType.GetFlattenedProperties().AsList();
            var values = new object?[properties.Count];

            for (var i = 0; i < properties.Count; i++)
            {
                var property = properties[i];
                var targetObject = NavigateToDeclaringType(complexObject, property.DeclaringType, complexType);
                values[i] = targetObject == null ? null : property.GetGetter().GetClrValue(targetObject);
            }

            var complexPropertyValues = new ArrayPropertyValues(entry, values, null);

            foreach (var nestedComplexProperty in complexPropertyValues.ComplexCollectionProperties)
            {
                var targetObject = NavigateToDeclaringType(complexObject, nestedComplexProperty.DeclaringType, complexType);
                var nestedCollection = targetObject == null ? null : (IList?)nestedComplexProperty.GetGetter().GetClrValue(targetObject);
                var nestedPropertyValuesList = GetComplexCollectionPropertyValues(nestedComplexProperty, nestedCollection);
                complexPropertyValues.SetComplexCollectionValue(nestedComplexProperty, nestedPropertyValuesList);
            }

            return complexPropertyValues;
        }

        static object? NavigateToDeclaringType(object root, ITypeBase declaringType, IRuntimeTypeBase rootType)
        {