Because the in modifier applies only to the variable (the parameter in this case). It prevents the parameter from having its value changed to refer to a different object.
public bool Migrate(in Catalog fromCatalog)
{
/* Error CS8331 Cannot assign to variable 'fromCatalog'
or use it as the right hand side of a ref assignment
because it is a readonly variable */
fromCatalog = new Catalog();
fromCatalog.SupplierId = 1;
}
and create a shallow copy of the object so that you don't change anything in the object you passed (within the class)
example:
public Catalog CreateACopy()
{
Catalog obj = (Catalog)this.MemberwiseClone();
// and other...
return obj;
}
utilization:
public class Program
{
private static void Main()
{
Catalog catalog = new Catalog();
new Program().Migrate(catalog.CreateACopy());
}
public bool Migrate(in Catalog fromCatalog)
{
fromCatalog.SupplierId = 1;
}
}