|
14 | 14 | */ |
15 | 15 |
|
16 | 16 | using System; |
17 | | -using System.Linq; |
18 | | -using System.Linq.Expressions; |
19 | | -using System.Threading; |
20 | | -using MongoDB.Bson; |
21 | | -using MongoDB.Bson.Serialization; |
22 | 17 |
|
23 | 18 | namespace MongoDB.Driver.Linq |
24 | 19 | { |
25 | 20 | /// <summary> |
26 | 21 | /// Represents the different LINQ providers. |
27 | 22 | /// </summary> |
28 | | - public abstract class LinqProvider |
| 23 | + public enum LinqProvider |
29 | 24 | { |
30 | | - #region static |
31 | | - // public static fields |
32 | 25 | /// <summary> |
33 | 26 | /// The LINQ provider that was first shipped with version 2.0 of the driver, |
34 | 27 | /// </summary> |
35 | | - public static readonly LinqProvider V2 = new Linq2Implementation.LinqProviderV2(); |
| 28 | + V2 = 2, |
36 | 29 |
|
37 | 30 | /// <summary> |
38 | 31 | /// The LINQ provider that is planned to be the default in version 3.0 of the driver and can be optionally used before that. |
39 | 32 | /// </summary> |
40 | | - public static readonly LinqProvider V3 = new Linq3Implementation.LinqProviderV3(); |
41 | | - #endregion |
42 | | - |
43 | | - // internal methods |
44 | | - internal abstract IMongoQueryable<TDocument> AsQueryable<TDocument>( |
45 | | - IMongoCollection<TDocument> collection, |
46 | | - IClientSessionHandle session, |
47 | | - AggregateOptions options); |
48 | | - |
49 | | - internal abstract BsonValue TranslateExpressionToAggregateExpression<TSource, TResult>( |
50 | | - Expression<Func<TSource, TResult>> expression, |
51 | | - IBsonSerializer<TSource> sourceSerializer, |
52 | | - IBsonSerializerRegistry serializerRegistry, |
53 | | - ExpressionTranslationOptions translationOptions); |
54 | | - |
55 | | - internal abstract RenderedProjectionDefinition<TOutput> TranslateExpressionToBucketOutputProjection<TInput, TValue, TOutput>( |
56 | | - Expression<Func<TInput, TValue>> valueExpression, |
57 | | - Expression<Func<IGrouping<TValue, TInput>, TOutput>> outputExpression, |
58 | | - IBsonSerializer<TInput> documentSerializer, |
59 | | - IBsonSerializerRegistry serializerRegistry, |
60 | | - ExpressionTranslationOptions translationOptions); |
61 | | - |
62 | | - internal abstract RenderedFieldDefinition TranslateExpressionToField<TDocument>( |
63 | | - LambdaExpression expression, |
64 | | - IBsonSerializer<TDocument> documentSerializer, |
65 | | - IBsonSerializerRegistry serializerRegistry); |
66 | | - |
67 | | - internal abstract RenderedFieldDefinition<TField> TranslateExpressionToField<TDocument, TField>( |
68 | | - Expression<Func<TDocument, TField>> expression, |
69 | | - IBsonSerializer<TDocument> documentSerializer, |
70 | | - IBsonSerializerRegistry serializerRegistry, |
71 | | - bool allowScalarValueForArrayField); |
72 | | - |
73 | | - internal abstract BsonDocument TranslateExpressionToFilter<TDocument>( |
74 | | - Expression<Func<TDocument, bool>> expression, |
75 | | - IBsonSerializer<TDocument> documentSerializer, |
76 | | - IBsonSerializerRegistry serializerRegistry); |
77 | | - |
78 | | - internal abstract RenderedProjectionDefinition<TProjection> TranslateExpressionToFindProjection<TSource, TProjection>( |
79 | | - Expression<Func<TSource, TProjection>> expression, |
80 | | - IBsonSerializer<TSource> sourceSerializer, |
81 | | - IBsonSerializerRegistry serializerRegistry); |
82 | | - |
83 | | - internal abstract RenderedProjectionDefinition<TOutput> TranslateExpressionToGroupProjection<TInput, TKey, TOutput>( |
84 | | - Expression<Func<TInput, TKey>> idExpression, |
85 | | - Expression<Func<IGrouping<TKey, TInput>, TOutput>> groupExpression, |
86 | | - IBsonSerializer<TInput> documentSerializer, |
87 | | - IBsonSerializerRegistry serializerRegistry, |
88 | | - ExpressionTranslationOptions translationOptions); |
| 33 | + V3 = 3 |
| 34 | + } |
89 | 35 |
|
90 | | - internal abstract RenderedProjectionDefinition<TOutput> TranslateExpressionToProjection<TInput, TOutput>( |
91 | | - Expression<Func<TInput, TOutput>> expression, |
92 | | - IBsonSerializer<TInput> inputSerializer, |
93 | | - IBsonSerializerRegistry serializerRegistry, |
94 | | - ExpressionTranslationOptions translationOptions); |
| 36 | + internal static class LinqProviderExtensions |
| 37 | + { |
| 38 | + public static LinqProviderAdapter GetAdapter(this LinqProvider linqProvider) |
| 39 | + { |
| 40 | + return linqProvider switch |
| 41 | + { |
| 42 | + LinqProvider.V2 => LinqProviderAdapter.V2, |
| 43 | + LinqProvider.V3 => LinqProviderAdapter.V3, |
| 44 | + _ => throw new ArgumentException($"Unknown LINQ provider: {linqProvider}.", nameof(linqProvider)) |
| 45 | + }; |
| 46 | + } |
95 | 47 | } |
96 | 48 | } |
0 commit comments