Skip to content

Commit 21d51ff

Browse files
committed
Modified VS-99 Changes
1 parent 0e983cc commit 21d51ff

File tree

5 files changed

+22
-33
lines changed

5 files changed

+22
-33
lines changed

src/MongoDB.Analyzer.Helpers/Builders/MqlGenerator.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,17 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
using MongoDB.Driver;
1615
using System.Linq;
17-
using BsonDocumentCustom123 = MongoDB.Bson.BsonDocument;
18-
using BsonValueCustom123 = MongoDB.Bson.BsonValue;
19-
using BsonObjectIdCustom123 = MongoDB.Bson.BsonObjectId;
20-
using BsonTypeCustom123 = MongoDB.Bson.BsonType;
21-
using BsonTimeSpanCustom123 = MongoDB.Bson.Serialization.Options.TimeSpanUnits;
16+
using MongoDB.Bson;
17+
using MongoDB.Driver;
2218

2319
namespace MongoDB.Analyzer.Helpers.Builders
2420
{
2521
public static class MqlGenerator
2622
{
2723
#pragma warning disable CS0169 // The field is never used
2824
#pragma warning disable IDE0051
29-
private static readonly BsonDocumentCustom123 s_dummyRef1;
30-
private static readonly BsonValueCustom123 s_dummyRef2;
31-
private static readonly BsonObjectIdCustom123 s_dummyRef3;
32-
private static readonly BsonTypeCustom123 s_dummyRef4;
33-
private static readonly BsonTimeSpanCustom123 s_dummyRef5;
25+
private static readonly BsonType s_dummyRef1;
3426
#pragma warning restore IDE0051 // The field is never used
3527
#pragma warning restore CS0169
3628

src/MongoDB.Analyzer.Helpers/Linq/MqlGenerator.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@
1414

1515
using System;
1616
using System.Linq;
17+
using MongoDB.Bson;
1718
using MongoDB.Driver.Linq;
18-
using BsonTypeCustom123 = MongoDB.Bson.BsonType;
19-
using BsonTimeSpanCustom123 = MongoDB.Bson.Serialization.Options.TimeSpanUnits;
2019

2120
namespace MongoDB.Analyzer.Helpers.Linq
2221
{
2322
public static class MqlGenerator
2423
{
2524
#pragma warning disable CS0169 // The field is never used
2625
#pragma warning disable IDE0051
27-
private static readonly BsonTypeCustom123 s_dummyRef1;
28-
private static readonly BsonTimeSpanCustom123 s_dummyRef2;
26+
private static readonly BsonType s_dummyRef1;
2927
#pragma warning restore IDE0051 // The field is never used
3028
#pragma warning restore CS0169
3129

src/MongoDB.Analyzer/Core/TypesGeneratorHelper.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ internal static class TypesGeneratorHelper
2222
.AddUsings(
2323
Using("System"),
2424
Using("MongoDB.Bson"),
25-
Using("MongoDB.Bson.Serialization.Attributes"),
26-
Using("BsonTimeSpanCustom123", "MongoDB.Bson.Serialization.Options.TimeSpanUnits"),
27-
Using("BsonTypeCustom123", "MongoDB.Bson.BsonType"),
28-
Using("BsonDocumentCustom123", "MongoDB.Bson.BsonDocument"),
29-
Using("BsonValueCustom123", "MongoDB.Bson.BsonValue"),
30-
Using("BsonObjectIdCustom123", "MongoDB.Bson.BsonObjectId"));
25+
Using("MongoDB.Bson.Serialization.Attributes"));
3126

3227

3328
private static readonly NamespaceDeclarationSyntax s_namespaceDeclarationSyntaxBuilders = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName(MqlGeneratorSyntaxElements.Builders.MqlGeneratorNamespace));

src/MongoDB.Analyzer/Core/TypesProcessor.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ namespace MongoDB.Analyzer.Core;
1616

1717
internal sealed class TypesProcessor
1818
{
19-
private static readonly Dictionary<string, string> s_knownBsonTypes = new()
20-
{
21-
{ "MongoDB.Bson.BsonDocument", "BsonDocumentCustom123" },
22-
{ "MongoDB.Bson.BsonValue", "BsonValueCustom123" },
23-
{ "MongoDB.Bson.BsonObjectId", "BsonObjectIdCustom123" },
24-
{ "MongoDB.Bson.BsonType", "BsonTypeCustom123" },
25-
{ "MongoDB.Bson.Serialization.Options.TimeSpanUnits", "BsonTimeSpanCustom123" }
26-
};
27-
2819
private readonly Dictionary<string, (string NewName, MemberDeclarationSyntax NewDeclaration)> _processedTypes;
2920

3021
private int _nextTypeId = 0;
@@ -73,9 +64,9 @@ public string ProcessTypeSymbol(ITypeSymbol typeSymbol)
7364
}
7465

7566
var fullTypeName = GetFullName(typeSymbol);
76-
if (s_knownBsonTypes.TryGetValue(fullTypeName, out var knowTypeName))
67+
if (typeSymbol.IsSupportedBsonType())
7768
{
78-
return (knowTypeName, fullTypeName);
69+
return (typeSymbol.Name, fullTypeName);
7970
}
8071

8172
if (_processedTypes.TryGetValue(fullTypeName, out var result))

src/MongoDB.Analyzer/Core/Utilities/SymbolExtensions.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@ namespace MongoDB.Analyzer.Core;
1616

1717
internal 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

Comments
 (0)