Repository: microsoft/semantic-kernel
File: dotnet/src/Connectors/VectorData.Abstractions/ProviderServices/PropertyModel.cs (C#)

Code before:
                return;
            }

            throw new UnreachableException("Non-dynamic mapping but ClrProperty is null.");
        }

        // We have a CLR property (non-dynamic POCO mapping)

        // TODO: Implement compiled delegates for better performance, #11122
        // TODO: Implement source-generated accessors for NativeAOT, #10256

        // If the value is null, no need to set the property (it's the CLR default)
        if (value is not null)
        {
            this.PropertyInfo.SetValue(record, value);
        }
    }

    /// <summary>
    /// Reads the property from the given <paramref name="record"/>.
    /// </summary>
    // TODO: actually implement the generic accessors to avoid boxing, and make use of them in connectors
    public virtual T GetValue<T>(object record)
        => (T)(object)this.GetValueAsObject(record)!;

    /// <summary>
    /// Writes the property from the given <paramref name="record"/>.
    /// </summary>s
    // TODO: actually implement the generic accessors to avoid boxing, and make use of them in connectors
    public virtual void SetValue<T>(object record, T value)
    {
        this.SetValueAsObject(record, value);
    }
}


Review comment (suggestion):
These are here so that we can do reading/writing of properties without boxing. When we implement NativeAOT mode via source generation, the source-generated delegates should just support this; and we have the option of code-generating delegates dynamically for JIT mode if we want as well (for dynamic/Dictionary it makes no sense as values are boxed anyway within the Dictionary, as objects).

For now these are just here so we can start using them from provider code - even if they currently box behind the  scenes (because the call the object-based methods). But when we light up this capability, providers that do the right thing will simply stop boxing.


Code after:
            {
                var dictionary = (Dictionary<string, object?>)record;
                dictionary[this.ModelName] = value;
                return;
            }

            throw new UnreachableException("Non-dynamic mapping but ClrProperty is null.");
        }

        // We have a CLR property (non-dynamic POCO mapping)

        // TODO: Implement compiled delegates for better performance, #11122
        // TODO: Implement source-generated accessors for NativeAOT, #10256

        // If the value is null, no need to set the property (it's the CLR default)
        if (value is not null)
        {
            this.PropertyInfo.SetValue(record, value);
        }
    }

    /// <summary>
    /// Reads the property from the given <paramref name="record"/>.
    /// </summary>
    // TODO: actually implement the generic accessors to avoid boxing, and make use of them in connectors
    public virtual T GetValue<T>(object record)
        => (T)(object)this.GetValueAsObject(record)!;

    /// <summary>
    /// Writes the property from the given <paramref name="record"/>.
    /// </summary>s
    // TODO: actually implement the generic accessors to avoid boxing, and make use of them in connectors
    public virtual void SetValue<T>(object record, T value)
    {
        this.SetValueAsObject(record, value);
    }
}