private Document ConvertFieldSelectorToDocument(object document) { Document doc; if (document == null) { doc = new Document(); } else { doc = ConvertExampleToDocument(document) as Document; } if (doc == null) { throw new NotSupportedException("An entity type is not supported in field selection. Use either a document or an anonymous type."); } var classMap = _mappingStore.GetClassMap(typeof(T)); if (doc.Count > 0 && (classMap.IsPolymorphic || classMap.IsSubClass)) { doc[classMap.DiscriminatorAlias] = true; } return(doc.Count == 0 ? null : doc); }
private void MatchMembers() { Type currentType = _classMap.ClassType; Member: string memberName = MatchMember(); var classMap = _mappingStore.GetClassMap(currentType); var memberMap = classMap.GetMemberMapFromMemberName(memberName); if (memberMap == null) { _output.Append(memberName); return; } _output.Append(memberMap.Alias); currentType = memberMap.MemberReturnType; var c = ReadChar(true); if (c == '[') { MatchIndexer(); if (memberMap is CollectionMemberMap) { currentType = ((CollectionMemberMap)memberMap).ElementType; } c = ReadChar(true); } if (c == '.') { goto Member; } }
public object BeginObject(object instance) { if (instance is Document) { return(BeginDocument((Document)instance)); } var currentClassMap = _mappingStore.GetClassMap(_types.Peek()); var instanceType = instance.GetType(); if (!currentClassMap.ClassType.IsAssignableFrom(instanceType)) { return(new ExampleClassMapPropertyDescriptor(_mappingStore, currentClassMap, instance)); } if (currentClassMap.ClassType != instanceType) //we are a subclass { currentClassMap = _mappingStore.GetClassMap(instanceType); } return(new ClassMapPropertyDescriptor(_mappingStore, currentClassMap, instance)); }
/// <summary> /// Gets the class map for the specified class type. /// </summary> /// <param name = "classType">Type of the entity.</param> /// <returns></returns> public IClassMap GetClassMap(Type classType) { try { _lock.EnterUpgradeableReadLock(); IClassMap classMap; if (_autoMaps.TryGetValue(classType, out classMap)) { return(classMap); } if (_wrappedMappingStore != null) { classMap = _wrappedMappingStore.GetClassMap(classType); if (classMap != null) { return(classMap); } } classMap = _autoMapper.CreateClassMap(classType, GetClassMap); try { _lock.EnterWriteLock(); _autoMaps.Add(classType, classMap); return(classMap); } finally { if (_lock.IsWriteLockHeld) { _lock.ExitWriteLock(); } } } finally { if (_lock.IsUpgradeableReadLockHeld) { _lock.ExitUpgradeableReadLock(); } } }
public object BeginObject() { if (_isDictionary) { _isDictionary = false; return(new DictionaryBuilder(_types.Peek())); } if (_types.Peek() == null || _types.Peek() == typeof(Document)) { return(new DocumentBuilder()); } var classMap = _mappingStore.GetClassMap(_types.Peek()); if (classMap.IsPolymorphic) { //until we have the discriminator, we can't instantiate the type. return(new PolymorphicClassMapBuilder(classMap)); } return(new ConcreteClassMapBuilder(classMap)); }