public bool ResolveOptional(Type type, out DocumentMap map) { var maps = new List <DocumentMap>(); // Walk up the inheritance chain and make sure there's only one map for the document. var currentType = type; while (true) { if (mappings.TryGetValue(currentType, out var m)) { maps.Add(m); } currentType = currentType.GetTypeInfo().BaseType; if (currentType == typeof(object) || currentType == null) { break; } } if (maps.Count > 1) { throw new InvalidOperationException($"More than one document map is registered against the type '{type.FullName}'. The following maps could apply: " + string.Join(", ", maps.Select(m => m.GetType().FullName))); } map = maps.SingleOrDefault(); return(map != null); }
public bool TryGet(Type type, out DocumentMap map) { DocumentMap mapping = null; // Walk up the inheritance chain until we find a mapping var currentType = type; while (currentType != null && !mappings.TryGetValue(currentType, out mapping)) { currentType = currentType.GetTypeInfo().BaseType; } map = mapping; return(mapping != null); }
public DocumentMap Get(Type type) { DocumentMap mapping = null; // Walk up the inheritance chain until we find a mapping var currentType = type; while (currentType != null && !mappings.TryGetValue(currentType, out mapping)) { currentType = currentType.GetTypeInfo().BaseType; } if (mapping == null) { throw new KeyNotFoundException(string.Format("A mapping for the type '{0}' has not been defined", type.Name)); } return(mapping); }
public void Register(DocumentMap map) { map.Validate(); mappings[map.Type] = map; }
public StandardTypeResolver(DocumentMap mapper) { this.mapper = mapper; }
public bool TryGet(Type type, out DocumentMap map) { return(mappings.TryGetValue(type, out map)); }