generated from SwissLife-OSS/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apply indexes to primitive type values only
- Loading branch information
Showing
3 changed files
with
117 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using MongoDB.Bson; | ||
|
||
#nullable enable | ||
|
||
namespace Bewit.Storage.MongoDB | ||
{ | ||
public static class TypeChecker | ||
{ | ||
private static readonly HashSet<Type> PrimitiveTypes = new HashSet<Type> | ||
{ | ||
typeof(string), | ||
typeof(bool), | ||
typeof(byte), | ||
typeof(sbyte), | ||
typeof(char), | ||
typeof(decimal), | ||
typeof(double), | ||
typeof(float), | ||
typeof(int), | ||
typeof(uint), | ||
typeof(long), | ||
typeof(ulong), | ||
typeof(short), | ||
typeof(ushort), | ||
typeof(DateTime), | ||
typeof(DateTimeOffset), | ||
typeof(TimeSpan), | ||
typeof(DateOnly), | ||
typeof(TimeOnly), | ||
typeof(Guid), | ||
typeof(ObjectId), | ||
typeof(BsonObjectId), | ||
typeof(BsonDateTime) | ||
}; | ||
|
||
public static bool IsPrimitiveType(object value) | ||
{ | ||
if (value == null) | ||
return false; | ||
|
||
Type type = value.GetType(); | ||
return IsPrimitiveType(type); | ||
} | ||
|
||
public static bool IsPrimitiveType(Type type) | ||
{ | ||
Type underlyingType = Nullable.GetUnderlyingType(type) ?? type; | ||
|
||
return PrimitiveTypes.Contains(underlyingType) || | ||
underlyingType.IsEnum; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters