public override object Create(object[] parameters = null, object[] objectClasses = null) { if (HasSubTypeMappings && objectClasses != null) { IObjectMapping mapping; #if NET35 string joinedObjectClasses = string.Join(" ", objectClasses.Cast <string>().ToArray()); #else string joinedObjectClasses = string.Join(" ", objectClasses); #endif if (_fullObjectClassMappings.TryGetValue(joinedObjectClasses, out mapping)) { return(mapping.Create()); } //Reverse the object classes in order of most specific to least specific. //AD and openLDAP seem to retreive the classes in order of least to most specific so I assume it's the standard. if (objectClasses.Cast <string>().Reverse().Any(objectClass => SubTypeMappingsObjectClassDictionary.TryGetValue(objectClass, out mapping))) { _fullObjectClassMappings.TryAdd(joinedObjectClasses, mapping); return(mapping.Create()); } } return(_constructor()); }
public virtual void AddSubTypeMapping(IObjectMapping mapping) { if (WithoutSubTypeMapping || SubTypeMappingsObjectClassDictionary.Values.Contains(mapping)) { return; } var currentMappings = SortByInheritanceDescending(SubTypeMappingsObjectClassDictionary.Values.Union(new[] { mapping })); SubTypeMappingsObjectClassDictionary.Clear(); SubTypeMappingsTypeDictionary.Clear(); foreach (var currentMapping in currentMappings) { var objectClasses = currentMapping.ObjectClasses.ToList(); //find direct ancestor object classes or default to this class' object classes if a direct ancestor hasn't been mapped yet. var parentObjectClasses = currentMappings .Where(x => currentMapping.Type.IsSubclassOf(x.Type)) .Select(x => x.ObjectClasses) .FirstOrDefault() ?? ObjectClasses; objectClasses = objectClasses.Except(parentObjectClasses, StringComparer.OrdinalIgnoreCase).ToList(); if (objectClasses.Count == 0) { throw new InvalidOperationException("Unable to identify distinct object class based on mapped inheritance"); } SubTypeMappingsObjectClassDictionary.Add(objectClasses[0], currentMapping); SubTypeMappingsTypeDictionary.Add(currentMapping.Type, currentMapping); } _readOnlySubTypeMappings = null; _propertyNames = InitializePropertyNames(); }