public NodeMappingExpression(NodeMappingEngine engine, NodeMapper mapping) { if (mapping == null) { throw new ArgumentNullException("mapping"); } else if (mapping == null) { throw new ArgumentNullException("engine"); } _nodeMapper = mapping; _engine = engine; }
public NodeQuery(NodeMappingEngine engine) { var destinationType = typeof(TDestination); if (engine == null) { throw new ArgumentNullException("engine"); } else if (!engine.NodeMappers.ContainsKey(destinationType)) { throw new MapNotFoundException(destinationType); } _engine = engine; _paths = new List <string>(); _propertyFilters = new Dictionary <string, Func <object, bool> >(); }
public NodeMapper(NodeMappingEngine engine, Type destinationType, DocumentType sourceDocumentType) { if (sourceDocumentType == null) { throw new ArgumentNullException("sourceDocumentType"); } else if (engine == null) { throw new ArgumentNullException("engine"); } else if (destinationType == null) { throw new ArgumentNullException("destinationType"); } SourceDocumentType = sourceDocumentType; Engine = engine; DestinationType = destinationType; PropertyMappers = new List <PropertyMapperBase>(); // See if base properties have been mapped already. var baseNodeMapper = Engine.GetBaseNodeMapperForType(destinationType); if (baseNodeMapper != null) { // Use the property mappings of the closest parent // (ideally they will already have the mappings of all their ancestors) PropertyMappers.AddRange(baseNodeMapper.PropertyMappers); } // Map properties foreach (var destinationProperty in destinationType.GetProperties()) { if (PropertyMappers.Any(mapper => mapper.DestinationInfo.Name == destinationProperty.Name) || !destinationProperty.CanWrite) { // A mapping already exists for this property on a base type or its a ReadOnly property. continue; } PropertyMapperBase propertyMapper = null; var sourcePropertyAlias = GetPropertyAlias(destinationProperty); // Check if this property is equivalent to a default Node property. var defaultNodeProperty = DefaultPropertyMapper.GetDefaultMappingForName(destinationProperty); if (sourcePropertyAlias != null && // check corresponding source property alias was found destinationProperty.PropertyType.GetMappedPropertyType() == MappedPropertyType.SystemOrEnum) { propertyMapper = new BasicPropertyMapper( x => x, // direct mapping destinationProperty.PropertyType, // using the desired type this, destinationProperty, sourcePropertyAlias ); } else if (destinationProperty.PropertyType.GetMappedPropertyType() == MappedPropertyType.Model) { propertyMapper = new SinglePropertyMapper( null, null, this, destinationProperty, sourcePropertyAlias // can be null to map ancestor ); } else if (destinationProperty.PropertyType.GetMappedPropertyType() == MappedPropertyType.Collection) { propertyMapper = new CollectionPropertyMapper( null, null, this, destinationProperty, sourcePropertyAlias // can be null to map descendants ); } else if (defaultNodeProperty != null) { propertyMapper = new DefaultPropertyMapper( this, destinationProperty, defaultNodeProperty, null ); } if (propertyMapper != null) { PropertyMappers.Add(propertyMapper); } } }