private void ThrowExceptionIfNotClonable(CloningTypeMetadata typeMetadata) { if (!typeMetadata.Clonable) { throw new InvalidOperationException(string.Format("The type {0} is not clonable (e.g. the MetadataCollector (of type {1}) could not provider any metadata)", typeMetadata.TargetType, this.collector.GetType())); } }
private static object CreateNewInstance(CloningTypeMetadata typeMetadata) { return typeMetadata.Factory.CreateNew(typeMetadata); }
private IDictionary<string, object> CloneProperties(object obj, CloningTypeMetadata typeMetadata) { IDictionary<string, object> clonedPropertyValues = new Dictionary<string, object>(); foreach (string propertyName in typeMetadata.GetPropertyNames()) { CloningPropertyMetadata propertyMetadata = typeMetadata.GetMetaDataForProperty(propertyName); object clonedValue = propertyMetadata.Action.Clone(this, propertyName, obj); clonedPropertyValues.Add(propertyName, clonedValue); } return clonedPropertyValues; }