I have the following problem. I want to be able to set this to the passed reference without using reflection, can this be done?
//partial class of a Linq-to-SQL class
public partial class Product
{
public Product (Product product, List<ProductAttributes> productAttributes)
{
// without individually setting all the properties
//then just set any other properties
this.ProductAttributes = productAttributes;
}
}
You cannot set
thisin reference types (and setting it in value types is probably not something to be condoned). If what you’re looking to do is a shallow (or deep) copy of the object’s fields or properties, then you have two choices:Neither the language nor the runtime have any built-in facility for automating shallow or deep copying, and for good reason. It would be impossible to determine what that would look like for any given type.