public DictionaryDocumentInfo() { if (_type.TryGetImplementingGenericType(out var dictionaryType, typeof(IDictionary <,>)) || _type.TryGetImplementingGenericType(out dictionaryType, typeof(IReadOnlyDictionary <,>))) { var arguments = dictionaryType.GetGenericArguments(); _dictionaryKeyType = arguments[0]; _dictionaryValueType = arguments[1]; _documentFieldInfo = new DocumentFieldInfo(_dictionaryValueType); if (_type == dictionaryType) { _creatorType = CreatorType.SpecifiedTypeDictionary; _dictionaryAdapterFactoryType = DictionaryAdapterFactoryType.NonGeneric; } else { _creatorType = CreatorType.SpecifiedType; _dictionaryAdapterFactoryType = DictionaryAdapterFactoryType.Generic; } }
public DictionaryDocumentInfo(Type implementingType) { if (implementingType.IsGenericType) { var arguments = implementingType.GetGenericArguments(); _dictionaryKeyType = arguments[0]; _dictionaryValueType = arguments[1]; _documentFieldInfo = new DocumentFieldInfo(_dictionaryValueType); _dictionaryAdapterFactoryType = DictionaryAdapterFactoryType.Generic; _creatorType = _type.IsInterface ? CreatorType.SpecifiedTypeDictionary : CreatorType.SpecifiedType; } else { _dictionaryKeyType = typeof(string); _dictionaryValueType = typeof(object); _documentFieldInfo = new DocumentFieldInfo(_dictionaryValueType); _dictionaryAdapterFactoryType = DictionaryAdapterFactoryType.NonGeneric; _creatorType = _type.IsInterface ? CreatorType.ObjectDictionary : CreatorType.SpecifiedType; } }