public static IModelMapInstruction CloneInstruction(IModelMapInstruction instruction) { var cloneable = instruction as ICloneable; if (cloneable != null) { return((IModelMapInstruction)cloneable.Clone()); } var type = instruction.GetType(); var clone = (IModelMapInstruction)FastYetSimpleTypeActivator.CreateInstance(type); var properties = type.GetProperties(); foreach (var property in properties) { if (!property.CanWrite) { continue; } property.SetValue(clone, property.GetValue(instruction, null)); } return(clone); }
public void creates_different_object_each_time() { var result1 = FastYetSimpleTypeActivator.CreateInstance(_type); var result2 = FastYetSimpleTypeActivator.CreateInstance(_type); result1.ShouldNotBeTheSameAs(result2); }
public void Visit(BeginTransform instruction) { var name = instruction.Name.Resolve(_services).ToString(); if (!_registry.HasPolicy(name)) { throw new ModelMapException("Invalid transform: \"{0}\"".ToFormat(instruction.Name)); } _transform = (IMappingTransform)FastYetSimpleTypeActivator.CreateInstance(_registry.FindPolicy(name)); }
public bool ExecuteCondition(ActEntryConditionContext context) { var name = Condition.Resolve(context.Services).ToString(); var registry = context.Service <IActEntryConditionRegistry>(); if (!registry.HasCondition(name)) { throw new ModelMapException("Could not find condition: \"{0}\"".ToFormat(name)); } var type = registry.FindCondition(name); var condition = (IActEntryCondition)FastYetSimpleTypeActivator.CreateInstance(type); return(condition.ShouldExecute(context)); }
private MODEL[] createDtosForMap(ClarifyGenericMapEntry genericMap, IEnumerable <ClarifyDataRow> records) { var dtos = new List <MODEL>(); foreach (var record in records) { var dto = FastYetSimpleTypeActivator.CreateInstance(genericMap.Model.ModelType); populateDTOForGenericRecord(genericMap, record, dto); dtos.Add((MODEL)dto); } return(dtos.ToArray()); }
public void Visit(BeginCancellationPolicy instruction) { executeInstruction(() => { var name = instruction.Name.Resolve(_services).ToString(); if (!_registry.HasPolicy(name)) { throw new ModelMapException("Could not find cancellation policy: \"{0}\"".ToFormat(name)); } var type = _registry.FindPolicy(name); if (!type.CanBeCastTo <CancellationPolicy>()) { throw new ModelMapException("\"{0}\" does not inherit from CancellationPolicy".ToFormat(name)); } _transform = (IMappingTransform)FastYetSimpleTypeActivator.CreateInstance(_registry.FindPolicy(name)); }); }
private void populateDTOWithRelatedDTOs(ClarifyGenericMapEntry parentGenericMap, ClarifyDataRow parentRecord, object parentDto) { var childMapsForChildDtos = parentGenericMap.ChildGenericMaps.Where(child => parentDto.GetType() != child.Model.ModelType); foreach (var childMap in childMapsForChildDtos) { var parentProperty = new SingleProperty(childMap.Model.ParentProperty); var childModelType = childMap.Model.ModelType; if (typeof(IEnumerable).IsAssignableFrom(parentProperty.PropertyType)) { var propertyDTOs = new ArrayList(); foreach (var childRecord in parentRecord.RelatedRows(childMap.ClarifyGeneric)) { var propertyDTO = FastYetSimpleTypeActivator.CreateInstance(childModelType); populateDTOForGenericRecord(childMap, childRecord, propertyDTO); propertyDTOs.Add(propertyDTO); } parentProperty.SetValue(parentDto, propertyDTOs.ToArray(childModelType)); } else //dto is not enumerable just get the first child row { var relatedChildRows = parentRecord.RelatedRows(childMap.ClarifyGeneric); if (relatedChildRows.Any()) { var propertyDTO = FastYetSimpleTypeActivator.CreateInstance(childModelType); var childRecord = relatedChildRows.First(); populateDTOForGenericRecord(childMap, childRecord, propertyDTO); parentProperty.SetValue(parentDto, propertyDTO); } else { parentProperty.SetValue(parentDto, null); } } } }
public void cannot_create_types_without_default_ctor() { typeof(ArgumentException).ShouldBeThrownBy(() => FastYetSimpleTypeActivator.CreateInstance(typeof(String))); }
public void create_object_via_type() { var result = FastYetSimpleTypeActivator.CreateInstance(_type); result.ShouldBeOfType(_type); }
public IModelMapInstruction WaitFor() { return((IModelMapInstruction)FastYetSimpleTypeActivator.CreateInstance(_waitFor)); }