In C#, if I return this, the value is copied
This is not true, at least for classes. Classes in C# are reference types, that means every variable of that type is actually a reference, so returning this
just returns a reference to the current instance.
So to do this, it's essentially the same in C#:
public class Foo
{
public Foo Transform(Bar bar)
{
// transform
return this;
}
public Foo TransformDifferently(Yay yay)
{
// transform
return this;
}
}
For value types, it should return a new instance of the type. Value types are supposed to be immutable, so if you've designed your struct
correctly, there should be no method which modifies the original. Transform
should modify a new version of the struct instead.