@@ -17,19 +17,13 @@ namespace MongoDB.Analyzer.Core;
1717internal static class SymbolExtensions
1818{
1919 private const string AssemblyMongoDBDriver = "MongoDB.Driver" ;
20+ private const string NamespaceMongoDBBson = "MongoDB.Bson" ;
2021 private const string NamespaceMongoDBBsonAttributes = "MongoDB.Bson.Serialization.Attributes" ;
2122 private const string NamespaceMongoDBDriver = "MongoDB.Driver" ;
2223 private const string NamespaceMongoDBLinq = "MongoDB.Driver.Linq" ;
2324 private const string NamespaceSystem = "System" ;
2425 private const string NamespaceSystemLinq = "System.Linq" ;
2526
26- private static readonly HashSet < string > s_supportedCollections = new ( )
27- {
28- "System.Collections.Generic.IEnumerable<T>" ,
29- "System.Collections.Generic.IList<T>" ,
30- "System.Collections.Generic.List<T>"
31- } ;
32-
3327 private static readonly HashSet < string > s_supportedBsonAttributes = new ( )
3428 {
3529 "BsonConstructorAttribute" ,
@@ -50,6 +44,22 @@ internal static class SymbolExtensions
5044 "BsonTimeSpanOptionsAttribute"
5145 } ;
5246
47+ private static readonly HashSet < string > s_supportedBsonTypes = new ( )
48+ {
49+ "MongoDB.Bson.BsonDocument" ,
50+ "MongoDB.Bson.BsonObjectId" ,
51+ "MongoDB.Bson.BsonType" ,
52+ "MongoDB.Bson.BsonValue" ,
53+ "MongoDB.Bson.Serialization.Options.TimeSpanUnits"
54+ } ;
55+
56+ private static readonly HashSet < string > s_supportedCollections = new ( )
57+ {
58+ "System.Collections.Generic.IEnumerable<T>" ,
59+ "System.Collections.Generic.IList<T>" ,
60+ "System.Collections.Generic.List<T>"
61+ } ;
62+
5363 private static readonly HashSet < string > s_supportedSystemTypes = new ( )
5464 {
5565 "System.DateTimeKind" ,
@@ -150,24 +160,16 @@ public static bool IsIQueryable(this ITypeSymbol typeSymbol) =>
150160 public static bool IsMongoQueryable ( this ITypeSymbol typeSymbol ) =>
151161 typeSymbol ? . Name == "MongoQueryable" ;
152162
153- public static bool IsSupportedCollection ( this ITypeSymbol typeSymbol ) =>
154- typeSymbol is INamedTypeSymbol namedTypeSymbol &&
155- s_supportedCollections . Contains ( namedTypeSymbol . ConstructedFrom ? . ToDisplayString ( ) ) ;
156-
157- public static bool IsSupportedMongoCollectionType ( this ITypeSymbol typeSymbol ) =>
158- typeSymbol . TypeKind == TypeKind . Class &&
159- ! typeSymbol . IsAnonymousType ;
163+ public static bool IsString ( this ITypeSymbol typeSymbol ) =>
164+ typeSymbol ? . SpecialType == SpecialType . System_String ;
160165
161166 public static bool IsSupportedBsonAttribute ( this ITypeSymbol typeSymbol ) =>
162167 s_supportedBsonAttributes . Contains ( typeSymbol ? . Name ) &&
163168 typeSymbol ? . ContainingNamespace ? . ToDisplayString ( ) == NamespaceMongoDBBsonAttributes ;
164169
165- public static bool IsString ( this ITypeSymbol typeSymbol ) =>
166- typeSymbol ? . SpecialType == SpecialType . System_String ;
167-
168- public static bool IsSupportedSystemType ( this ITypeSymbol typeSymbol ) =>
169- ( typeSymbol . SpecialType != SpecialType . None || s_supportedSystemTypes . Contains ( typeSymbol . ToDisplayString ( ) ) ) &&
170- typeSymbol ? . ContainingNamespace ? . ToDisplayString ( ) == NamespaceSystem ;
170+ public static bool IsSupportedBsonType ( this ITypeSymbol typeSymbol , string fullTypeName ) =>
171+ s_supportedBsonTypes . Contains ( fullTypeName ) &&
172+ ( typeSymbol ? . ContainingNamespace ? . ToDisplayString ( ) . StartsWith ( NamespaceMongoDBBson ) ?? false ) ;
171173
172174 public static bool IsSupportedBuilderType ( this ITypeSymbol typeSymbol ) =>
173175 typeSymbol ? . TypeKind switch
@@ -178,6 +180,18 @@ TypeKind.Enum or
178180 _ => false
179181 } ;
180182
183+ public static bool IsSupportedCollection ( this ITypeSymbol typeSymbol ) =>
184+ typeSymbol is INamedTypeSymbol namedTypeSymbol &&
185+ s_supportedCollections . Contains ( namedTypeSymbol . ConstructedFrom ? . ToDisplayString ( ) ) ;
186+
187+ public static bool IsSupportedMongoCollectionType ( this ITypeSymbol typeSymbol ) =>
188+ typeSymbol . TypeKind == TypeKind . Class &&
189+ ! typeSymbol . IsAnonymousType ;
190+
191+ public static bool IsSupportedSystemType ( this ITypeSymbol typeSymbol , string fullTypeName ) =>
192+ ( typeSymbol . SpecialType != SpecialType . None || s_supportedSystemTypes . Contains ( fullTypeName ) ) &&
193+ typeSymbol ? . ContainingNamespace ? . ToDisplayString ( ) == NamespaceSystem ;
194+
181195 public static bool IsSupportedIMongoCollection ( this ITypeSymbol typeSymbol ) =>
182196 typeSymbol . IsIMongoCollection ( ) &&
183197 typeSymbol is INamedTypeSymbol namedType &&
0 commit comments