Synchronous code

This commit is contained in:
sunkaixuan
2025-08-24 14:36:27 +08:00
parent cde0f2d92d
commit 72a96f5f46

View File

@@ -21,6 +21,7 @@ namespace SqlSugar.MongoDb
_context = context; _context = context;
_visitorContext = visitorContext; _visitorContext = visitorContext;
} }
public BsonValue Extract(Expression expr) public BsonValue Extract(Expression expr)
{ {
if (ExpressionTool.GetParameters(expr).Count == 0) if (ExpressionTool.GetParameters(expr).Count == 0)
@@ -46,7 +47,7 @@ namespace SqlSugar.MongoDb
{ {
return InvokeMongoMethod(name, out result, context, model); return InvokeMongoMethod(name, out result, context, model);
} }
else if (name.StartsWith("Add")) else if (IsAddMethod(name))
{ {
result = AddDateByType(name, context, model); result = AddDateByType(name, context, model);
} }
@@ -68,6 +69,7 @@ namespace SqlSugar.MongoDb
} }
} }
#region Core
private BsonValue InvokeMongoMethod(string name, out BsonValue result, MongoDbMethod context, MethodCallExpressionModel model) private BsonValue InvokeMongoMethod(string name, out BsonValue result, MongoDbMethod context, MethodCallExpressionModel model)
{ {
if (name == nameof(ToString)) if (name == nameof(ToString))
@@ -178,11 +180,6 @@ namespace SqlSugar.MongoDb
} }
} }
private static bool IsEndCondition(string name)
{
return name == "End";
}
public BsonValue BuildMongoSwitch(List<KeyValuePair<string, Expression>> ifConditions) public BsonValue BuildMongoSwitch(List<KeyValuePair<string, Expression>> ifConditions)
{ {
if (ifConditions == null || ifConditions.Count < 3) if (ifConditions == null || ifConditions.Count < 3)
@@ -257,7 +254,6 @@ namespace SqlSugar.MongoDb
return switchDoc; return switchDoc;
} }
private static string TransformMethodName(MethodCallExpression methodCallExpression, string name) private static string TransformMethodName(MethodCallExpression methodCallExpression, string name)
{ {
if (name == "ToDateTime") if (name == "ToDateTime")
@@ -288,9 +284,21 @@ namespace SqlSugar.MongoDb
} }
#endregion
#region Helper
private static bool IsEndCondition(string name)
{
return name == "End";
}
private static bool IsCountJson(MethodCallExpression methodCallExpression, string name) private static bool IsCountJson(MethodCallExpression methodCallExpression, string name)
{ {
return name == "Count" && methodCallExpression?.Arguments?.FirstOrDefault() is MemberExpression m; return name == "Count" && methodCallExpression?.Arguments?.FirstOrDefault() is MemberExpression m;
} }
private static bool IsAddMethod(string name)
{
return name.StartsWith("Add");
}
#endregion
} }
} }