Selective updates to immutable types There is a way in Scala to selectively change a field while making a copy of the immutable object:

case class Phone(areaCode: String, number: String) // declare type
val original = Phone("832","123-4567") // instantiate 
val changed = original.copy(areaCode = "425") // get an updated copy


While in C# it looks like a real pain as usual. One need to create copy ctor and modifiers:

public class Phone
{
    Phone(Phone source)
        : this(source.AreaCode, source.Number)
    {
    }

    public Phone(string areaCode, string number)
    {
        AreaCode = areaCode;
        Number = number;
    }

    public string AreaCode { get; private set; }
    public string Number { get; private set; }

    public Phone WithAreaCode(string value) =&gt; 
        new Phone(this) { AreaCode = value };

    public Phone WithNumber(string value) =&gt; 
        new Phone(this) { Number = value };
}


We are probably supposed to charge per line… 

Here is what I use to mitigate the problem. The immutable type is as easy as it could be:

public class Phone
{
    public Phone(string areaCode, string number)
    { AreaCode = areaCode; Number = number; }

    public string AreaCode { get; }
    public string Number { get; }
}


But there is an extension method to do the trick:

var original = new Phone("832", "123-4567");
var changed = original.With(p =&gt; p.AreaCode, "425");


which is defined as:

public static class Cloneable
{
    public static TSource With&lt;TSource, TProperty&gt;(this TSource source, Expression&lt;Func&lt;TSource, TProperty&gt;&gt; selector, TProperty value) =&gt; 
        source.With(new Binding(selector.Target(), value));

    static TSource With&lt;TSource&gt;(this TSource source, Binding change) =&gt;
        (TSource)Activator.CreateInstance(typeof(TSource), source.Parameters(change));

    static object[] Parameters&lt;TSource&gt;(this TSource source, Binding change)
    {
        var values = source.Values().Update(change)
            .ToDictionary(b =&gt; b.Name, b =&gt; b.Value, StringComparer.OrdinalIgnoreCase);

        return typeof(TSource).GetConstructors().Single().GetParameters()
            .Select(p =&gt; values[p.Name])
            .ToArray();
    }

    static IEnumerable&lt;Binding&gt; Values&lt;TSource&gt;(this TSource source) =&gt;
        typeof(TSource).GetProperties()
            .Select(p =&gt; new Binding(p.Name, p.GetValue(source)));

    static IEnumerable&lt;Binding&gt; Update(this IEnumerable&lt;Binding&gt; values, Binding change) =&gt;
        values.Select(b =&gt; b.Name == change.Name ? change : b);

    static string Target&lt;TSource, TProperty&gt;(this Expression&lt;Func&lt;TSource, TProperty&gt;&gt; selector) =&gt;
        selector.Body is MemberExpression member &amp;&amp; member.Member is PropertyInfo property
            ? property.Name
            : throw new ArgumentException();   

    class Binding
    {
        public Binding(string name, object value)
        { Name = name; Value = value; }

        public string Name { get; }
        public object Value { get; }
    }
}
You should be able to cut the code length and improve performance, by simplifying the algorithm. Here are some of the problems I've noticed in your implementation:


You're currently processing all of the type's properties, this is not necessary as you only need few concrete ones. There are few other problems deriving from this one.
You're creating the instance through the Activator class while you're also requesting the constructor of the class, since you already have the ConstructorInfo, it doesn't make much sense to call Activator.CreateInstance. Especially since the Activator is the slowest way to create an instance of a type. You should only stick to one of them, in this case you need information that is contained in the ConstructorInfo, I guess the choice is obvious.


A simpler version (using your Target method):

public static TSource With&lt;TSource, TProperty&gt;(this TSource source,
    Expression&lt;Func&lt;TSource, TProperty&gt;&gt; selector, TProperty value)
{
    var constructor = typeof(TSource).GetConstructors().Single();
    var parameters = GenerateParameters(source, constructor,
        new KeyValuePair&lt;string, object&gt;(selector.Target(), value)).ToArray();
    return (TSource) constructor.Invoke(parameters);
}

private static IEnumerable&lt;object&gt; GenerateParameters&lt;TSource&gt;(
    TSource source, ConstructorInfo ctor,
    KeyValuePair&lt;string, object&gt; parameterToModify)
{
    var type = typeof(TSource);
    foreach (var parameter in ctor.GetParameters())
    {
        if (string.Equals(parameter.Name, parameterToModify.Key, StringComparison.OrdinalIgnoreCase))
        {
            yield return parameterToModify.Value;
        }
        else
        {
            yield return type.GetProperty(parameter.Name,
                BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)?.GetValue(source);
        }
    }
}


I'm not a fan of long ternary operators, but if you prefer that you can always switch it. I don't really like KeyValuePair&lt;,&gt; either, but it makes sense to keep things coupled and adding a separate class seems somewhat redundant as it will be used only in 1 occasion.

This is the cleaner approach, but if you really want to squeeze a bit more performance you can avoid the .ToArray() call by creating an object[] instead of IEnumerable&lt;object&gt;:

public static TSource With&lt;TSource, TProperty&gt;(this TSource source,
    Expression&lt;Func&lt;TSource, TProperty&gt;&gt; selector, TProperty value)
{
    var constructor = typeof(TSource).GetConstructors().Single();
    return (TSource) constructor.Invoke(GenerateParameters(source, constructor,
        new KeyValuePair&lt;string, object&gt;(selector.Target(), value)));
}

private static object[] GenerateParameters&lt;TSource&gt;(
    TSource source, ConstructorInfo ctor,
    KeyValuePair&lt;string, object&gt; parameterToModify)
{
    var type = typeof(TSource);
    var ctorParameters = ctor.GetParameters();
    var parameters = new object[ctorParameters.Length];
    for (int i = 0; i &lt; parameters.Length; i++)
    {
        var ctorParameter = ctorParameters[i];
        if (string.Equals(ctorParameter.Name, parameterToModify.Key, StringComparison.OrdinalIgnoreCase))
        {
            parameters[i] = parameterToModify.Value;
        }
        else
        {
            parameters[i] = type.GetProperty(ctorParameter.Name,
                BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)?.GetValue(source);
        }
    }
    return parameters;
}


It's a bit longer, but it's not necessarily less readable, you can pick whatever suits you better.

P.S

Perhaps some caching mechanism would be useful, to improve performance of multiple sequential calls.