forked from mongodb/mongo-csharp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMqlMethod.cs
More file actions
135 lines (124 loc) · 8.32 KB
/
MqlMethod.cs
File metadata and controls
135 lines (124 loc) · 8.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Reflection;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
namespace MongoDB.Driver.Linq.Linq3Implementation.Reflection
{
internal static class MqlMethod
{
// private static fields
private static readonly MethodInfo __constantWithRepresentation;
private static readonly MethodInfo __constantWithSerializer;
private static readonly MethodInfo __convert;
private static readonly MethodInfo __createObjectId;
private static readonly MethodInfo __dateFromString;
private static readonly MethodInfo __dateFromStringWithFormat;
private static readonly MethodInfo __dateFromStringWithFormatAndTimezone;
private static readonly MethodInfo __dateFromStringWithFormatAndTimezoneAndOnErrorAndOnNull;
private static readonly MethodInfo __exists;
private static readonly MethodInfo __field;
private static readonly MethodInfo __hash;
private static readonly MethodInfo __hexHash;
private static readonly MethodInfo __isMissing;
private static readonly MethodInfo __isNullOrMissing;
private static readonly MethodInfo __sigmoid;
private static readonly MethodInfo __subtype;
// sets of methods
private static readonly IReadOnlyMethodInfoSet __dateFromStringOverloads;
private static readonly IReadOnlyMethodInfoSet __dateFromStringWithFormatOverloads;
private static readonly IReadOnlyMethodInfoSet __dateFromStringWithTimezoneOverloads;
private static readonly IReadOnlyMethodInfoSet __similarityFunctionOverloads;
// static constructor
static MqlMethod()
{
// initialize methods before sets of methods
__constantWithRepresentation = ReflectionInfo.Method((object value, BsonType representation) => Mql.Constant(value, representation));
__constantWithSerializer = ReflectionInfo.Method((object value, IBsonSerializer<object> serializer) => Mql.Constant(value, serializer));
__convert = ReflectionInfo.Method((object value, ConvertOptions<object> options) => Mql.Convert(value, options));
__createObjectId = ReflectionInfo.Method(() => Mql.CreateObjectId());
__dateFromString = ReflectionInfo.Method((string dateStringl) => Mql.DateFromString(dateStringl));
__dateFromStringWithFormat = ReflectionInfo.Method((string dateString, string format) => Mql.DateFromString(dateString, format));
__dateFromStringWithFormatAndTimezone = ReflectionInfo.Method((string dateString, string format, string timezone) => Mql.DateFromString(dateString, format, timezone));
__dateFromStringWithFormatAndTimezoneAndOnErrorAndOnNull = ReflectionInfo.Method((string dateString, string format, string timezone, DateTime? onError, DateTime? onNull) => Mql.DateFromString(dateString, format, timezone, onError, onNull));
__exists = ReflectionInfo.Method((object field) => Mql.Exists(field));
__field = ReflectionInfo.Method((object container, string fieldName, IBsonSerializer<object> serializer) => Mql.Field<object, object>(container, fieldName, serializer));
__hash = ReflectionInfo.Method((object value, MqlHashAlgorithm algorithm) => Mql.Hash(value, algorithm));
__hexHash = ReflectionInfo.Method((object value, MqlHashAlgorithm algorithm) => Mql.HexHash(value, algorithm));
__isMissing = ReflectionInfo.Method((object field) => Mql.IsMissing(field));
__isNullOrMissing = ReflectionInfo.Method((object field) => Mql.IsNullOrMissing(field));
__sigmoid = ReflectionInfo.Method((double value) => Mql.Sigmoid(value));
__subtype = ReflectionInfo.Method((object value) => Mql.Subtype(value));
var dotProductEnumerable = ReflectionInfo.Method((IEnumerable<object> vectors1, IEnumerable<object> vectors2, bool normalizeScore) => Mql.SimilarityDotProduct(vectors1, vectors2, normalizeScore));
var dotProductMemory = ReflectionInfo.Method((ReadOnlyMemory<object> vectors1, ReadOnlyMemory<object> vectors2, bool normalizeScore) => Mql.SimilarityDotProduct(vectors1, vectors2, normalizeScore));
var euclideanEnumerable = ReflectionInfo.Method((IEnumerable<object> vectors1, IEnumerable<object> vectors2, bool normalizeScore) => Mql.SimilarityEuclidean(vectors1, vectors2, normalizeScore));
var euclideanMemory = ReflectionInfo.Method((ReadOnlyMemory<object> vectors1, ReadOnlyMemory<object> vectors2, bool normalizeScore) => Mql.SimilarityEuclidean(vectors1, vectors2, normalizeScore));
var cosineEnumerable = ReflectionInfo.Method((IEnumerable<object> vectors1, IEnumerable<object> vectors2, bool normalizeScore) => Mql.SimilarityCosine(vectors1, vectors2, normalizeScore));
var cosineMemory = ReflectionInfo.Method((ReadOnlyMemory<object> vectors1, ReadOnlyMemory<object> vectors2, bool normalizeScore) => Mql.SimilarityCosine(vectors1, vectors2, normalizeScore));
// initialize sets of methods after methods
__dateFromStringOverloads = MethodInfoSet.Create(
[
__dateFromString,
__dateFromStringWithFormat,
__dateFromStringWithFormatAndTimezone,
__dateFromStringWithFormatAndTimezoneAndOnErrorAndOnNull
]);
__dateFromStringWithFormatOverloads = MethodInfoSet.Create(
[
__dateFromStringWithFormat,
__dateFromStringWithFormatAndTimezone,
__dateFromStringWithFormatAndTimezoneAndOnErrorAndOnNull
]);
__dateFromStringWithTimezoneOverloads = MethodInfoSet.Create(
[
__dateFromStringWithFormatAndTimezone,
__dateFromStringWithFormatAndTimezoneAndOnErrorAndOnNull
]);
__similarityFunctionOverloads = MethodInfoSet.Create(
[
dotProductEnumerable,
dotProductMemory,
euclideanEnumerable,
euclideanMemory,
cosineEnumerable,
cosineMemory,
]);
}
// public properties
public static MethodInfo ConstantWithRepresentation => __constantWithRepresentation;
public static MethodInfo ConstantWithSerializer => __constantWithSerializer;
public static MethodInfo Convert => __convert;
public static MethodInfo CreateObjectId => __createObjectId;
public static MethodInfo DateFromString => __dateFromString;
public static MethodInfo DateFromStringWithFormat => __dateFromStringWithFormat;
public static MethodInfo DateFromStringWithFormatAndTimezone => __dateFromStringWithFormatAndTimezone;
public static MethodInfo DateFromStringWithFormatAndTimezoneAndOnErrorAndOnNull => __dateFromStringWithFormatAndTimezoneAndOnErrorAndOnNull;
public static MethodInfo Exists => __exists;
public static MethodInfo Field => __field;
public static MethodInfo Hash => __hash;
public static MethodInfo HexHash => __hexHash;
public static MethodInfo IsMissing => __isMissing;
public static MethodInfo IsNullOrMissing => __isNullOrMissing;
public static MethodInfo Sigmoid => __sigmoid;
public static MethodInfo Subtype => __subtype;
// sets of methods
public static IReadOnlyMethodInfoSet DateFromStringOverloads => __dateFromStringOverloads;
public static IReadOnlyMethodInfoSet DateFromStringWithFormatOverloads => __dateFromStringWithFormatOverloads;
public static IReadOnlyMethodInfoSet DateFromStringWithTimezoneOverloads => __dateFromStringWithTimezoneOverloads;
public static IReadOnlyMethodInfoSet SimilarityFunctionOverloads => __similarityFunctionOverloads;
}
}