| | | 1 | | using System.Collections.Concurrent; |
| | | 2 | | using System.Reflection; |
| | | 3 | | |
| | | 4 | | namespace ArturRios.Data.MongoDb; |
| | | 5 | | |
| | | 6 | | /// <summary>Resolves the MongoDB collection name for a document type.</summary> |
| | | 7 | | public static class CollectionName |
| | | 8 | | { |
| | 1 | 9 | | private static readonly ConcurrentDictionary<Type, string> Cache = new(); |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Returns the <see cref="MongoCollectionAttribute" /> name for <typeparamref name="T" /> if present, |
| | | 13 | | /// otherwise the type name. |
| | | 14 | | /// </summary> |
| | | 15 | | public static string For<T>() where T : Document => |
| | 55 | 16 | | Cache.GetOrAdd(typeof(T), static t => t.GetCustomAttribute<MongoCollectionAttribute>()?.Name ?? t.Name); |
| | | 17 | | } |