@@ -16,13 +16,22 @@ namespace MongoDB.Analyzer.Core;
1616
1717internal static class SymbolExtensions
1818{
19- private const string AssemblyMongoDBDriver = "MongoDB.Driver " ;
19+ private const string NamespaceMongoDBBson = "MongoDB.Bson " ;
2020 private const string NamespaceMongoDBBsonAttributes = "MongoDB.Bson.Serialization.Attributes" ;
21+ private const string AssemblyMongoDBDriver = "MongoDB.Driver" ;
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
27+ private static readonly HashSet < string > s_knownBsonTypes = new ( )
28+ {
29+ "MongoDB.Bson.BsonDocument" ,
30+ "MongoDB.Bson.BsonValue" ,
31+ "MongoDB.Bson.BsonObjectId" ,
32+ "MongoDB.Bson.BsonType"
33+ } ;
34+
2635 private static readonly HashSet < string > s_supportedCollections = new ( )
2736 {
2837 "System.Collections.Generic.IEnumerable<T>" ,
@@ -162,6 +171,10 @@ public static bool IsSupportedBsonAttribute(this ITypeSymbol typeSymbol) =>
162171 s_supportedBsonAttributes . Contains ( typeSymbol ? . Name ) &&
163172 typeSymbol ? . ContainingNamespace ? . ToDisplayString ( ) == NamespaceMongoDBBsonAttributes ;
164173
174+ public static bool IsSupportedBsonType ( this ITypeSymbol typeSymbol ) =>
175+ typeSymbol ? . ContainingNamespace ? . ToDisplayString ( ) == NamespaceMongoDBBson &&
176+ s_knownBsonTypes . Contains ( typeSymbol . ToDisplayString ( ) ) ;
177+
165178 public static bool IsString ( this ITypeSymbol typeSymbol ) =>
166179 typeSymbol ? . SpecialType == SpecialType . System_String ;
167180
0 commit comments