public static Type GetPrimitiveElementType(Type collectionType) { var elementType = Utils.GetElementType(collectionType); if (elementType != null) { Utils.ValidatePrimitiveType(elementType); return(elementType); } throw new InvalidOperationException("Unable to determine element type"); }
private bool TryToScalar(object value, Type type, DynamoDBFlatConfig flatConfig, ref DynamoDBEntry entry) { var typeWrapper = TypeFactory.GetTypeInfo(type); var elementType = Utils.GetElementType(type); if (elementType != null) { IEnumerable enumerable = value as IEnumerable; // Strings are collections of chars, don't treat them as collections if (enumerable == null || value is string) { // Only convert if value matches collection element type if (TypeFactory.GetTypeInfo(value.GetType()).IsAssignableFrom(TypeFactory.GetTypeInfo(elementType))) { DynamoDBEntryConversion conversion = flatConfig.Conversion; if (conversion.HasConverter(elementType)) { if (conversion.TryConvertToEntry(elementType, value, out entry)) { return(true); } } else { try { entry = SerializeToDocument(value, elementType, flatConfig); return(true); } catch { } } } } } return(false); }