An application specific example to illustrate my immediate problem:
I have a metadata provider class with the following (abridged) interface:
public class CtsDataAnnotationsModelMetadataProvider : DataAnnotationsModelMetadataProvider
{
protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
{
var metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
return metadata;
}
}
Now I would like to extend ModelMetadata with additional properties, populate these and return and instance of ExtendedModelMetadata. How can I nicely convey properties assigned to the metadata instance by base.CreateMetadata in my extended instance? What I would like but don’t have is;
var metadata = (ExtendedModelMetadata)base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
I can create a constructor for ExtendedModelMetadata that takes a ModelMetadata parameter and explicitly assigns all of it’s properties to the instance being constructed, but I would like a more generic and less hard-coded approach for this. What can I do?
You can use AutoMapper to achieve this.
.NET Framework does not provide a deep copy feature.