diff --git a/Ctoss.Example/Program.cs b/Ctoss.Example/Program.cs index 6af4283..35167f8 100644 --- a/Ctoss.Example/Program.cs +++ b/Ctoss.Example/Program.cs @@ -12,9 +12,10 @@ .Entity() .Property("virtual", x => (x.SubEntity == null ? -1 : x.SubEntity.A) + (x.SubEntity == null ? -1 : x.SubEntity.B)) + .Property("mc", x => int.Parse(x.A.ToString())) .Apply() .Entity() - .Property(x => x.TextField, settings => { settings.IgnoreCase = true;}) + .Property(x => x.TextField, settings => { settings.IgnoreCase = true; }) .Apply(); const string jsonFilter = @@ -43,7 +44,7 @@ const string jsonNumericFilter = """ { - "virtual": { + "mc": { "filterType": "number", "condition1": { "filterType": "number", @@ -116,7 +117,8 @@ .WithPagination(1, 10) .ToList(); -foreach (var entity in numericEntities) Console.WriteLine($"A: {entity.A}, B: {entity.B}, SubEntity = ({entity.SubEntity.A + entity.SubEntity.B})"); +foreach (var entity in numericEntities) + Console.WriteLine($"A: {entity.A}, B: {entity.B}, SubEntity = ({entity.SubEntity.A + entity.SubEntity.B})"); Console.WriteLine("\nText entities:"); @@ -125,8 +127,8 @@ TextField = "abc" }; -var textEntities = new List {textEntity}.AsQueryable() +var textEntities = new List { textEntity }.AsQueryable() .WithFilter(jsonTextFilter) // <-- This is the extension method from the ctoss library .ToList(); -foreach (var entity in textEntities) Console.WriteLine(entity.TextField); +foreach (var entity in textEntities) Console.WriteLine(entity.TextField); \ No newline at end of file diff --git a/Ctoss/Configuration/CtossSettings.cs b/Ctoss/Configuration/CtossSettings.cs index c0da728..4090fdb 100644 --- a/Ctoss/Configuration/CtossSettings.cs +++ b/Ctoss/Configuration/CtossSettings.cs @@ -29,11 +29,16 @@ public static class CtossSettings if (propertyMapping == null) return null; - var unaryExpression = (UnaryExpression)propertyMapping.Body; - var binaryExpression = (BinaryExpression)unaryExpression.Operand; - - var resultType = binaryExpression.Type; - return resultType; + var expression = propertyMapping.Body; + + return expression switch + { + UnaryExpression unaryExpression => unaryExpression.Operand.Type, + BinaryExpression binaryExpression => binaryExpression.Type, + MethodCallExpression methodCallExpression => methodCallExpression.Method.ReturnType, + MemberExpression memberExpression => memberExpression.Type, + _ => throw new InvalidOperationException($"Unhandled expression type: {expression.GetType().Name}") + }; } internal static PropertySettings? GetPropertySettings(string propertyName)