Skip to content

Commit 15e3590

Browse files
Some reverting and validation and it's all fixed!
1 parent 676f824 commit 15e3590

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

Magic.IndexedDb/Helpers/MagicSerializationHelper.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ public static async Task SerializeObjectToStreamAsync<T>(StreamWriter writer, T
5454
await writer.FlushAsync();
5555
}
5656

57-
public static string SerializeObject<T>(T value, MagicJsonSerializationSettings? settings = null)
57+
public static string SerializeObject<T>(T? value, MagicJsonSerializationSettings? settings = null)
5858
{
59+
if (value == null)
60+
return "null";
61+
5962
if (settings == null)
6063
settings = new MagicJsonSerializationSettings();
6164

Magic.IndexedDb/IndexDbManager.cs

+1-16
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ void TraverseExpression(Expression expression, bool inOrBranch = false)
310310
{
311311
if (expression is BinaryExpression binaryExpression)
312312
{
313-
if (binaryExpression.NodeType == ExpressionType.AndAlso
314-
|| binaryExpression.NodeType == ExpressionType.NotEqual)
313+
if (binaryExpression.NodeType == ExpressionType.AndAlso)
315314
{
316315
TraverseExpression(binaryExpression.Left, inOrBranch);
317316
TraverseExpression(binaryExpression.Right, inOrBranch);
@@ -384,20 +383,6 @@ void AddCondition(Expression expression, bool inOrBranch)
384383
throw new InvalidOperationException($"Unsupported binary expression. Expression: {expression}");
385384
}
386385
}
387-
else if (expression is UnaryExpression unaryExpression && unaryExpression.NodeType == ExpressionType.Not)
388-
{
389-
if (unaryExpression.Operand is MethodCallExpression innerMethodCall)
390-
{
391-
if (innerMethodCall.Method.DeclaringType == typeof(string) && innerMethodCall.Method.Name == "Equals")
392-
{
393-
var left = innerMethodCall.Object as MemberExpression;
394-
var right = ToConstantExpression(innerMethodCall.Arguments[0]);
395-
396-
AddConditionInternal(left, right, "NotEquals", inOrBranch, false);
397-
return;
398-
}
399-
}
400-
}
401386
else if (expression is MethodCallExpression methodCallExpression)
402387
{
403388
if (methodCallExpression.Method.DeclaringType == typeof(string) &&

TestWasm/Pages/Home.razor

+18-10
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
new Person { Name = "Jack", TestInt = 9, DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 37, GUIY = Guid.NewGuid(), DoNotMapTest = "I have a drug problem", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite},
132132
new Person { Name = "Cathy", TestInt = 9, DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 22, GUIY = Guid.NewGuid(), DoNotMapTest = "I got away with reading Bobs diary.", Access = Person.Permissions.CanRead | Person.Permissions.CanWrite},
133133
new Person { Name = "Bob", TestInt = 3 , DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 69, GUIY = Guid.NewGuid(), DoNotMapTest = "I caught Cathy reading my diary, but I'm too shy to confront her.", Access = Person.Permissions.CanRead },
134-
new Person { Name = "Alex", TestInt = 3 , DateOfBirth = GetDateWithSameMonthDay(GetRandomYear()), _Age = 80, GUIY = Guid.NewGuid(), DoNotMapTest = "I'm naked! But nobody can know!" },
134+
new Person { Name = "Alex", TestInt = 3 , DateOfBirth = null, _Age = 80, GUIY = Guid.NewGuid(), DoNotMapTest = "I'm naked! But nobody can know!" },
135135
new Person { Name = "Zapoo", DateOfBirth = null, TestInt = 9, _Age = 45, GUIY = Guid.NewGuid(), DoNotMapTest = "I buried treasure behind my house", Access=Person.Permissions.CanRead},
136136

137137
};
@@ -151,16 +151,24 @@
151151
// || x.Name.Contains("bo", StringComparison.OrdinalIgnoreCase)
152152
// ).OrderBy(x => x._Id).Skip(1).AsAsyncEnumerable()).ToListAsync();
153153
154-
// WhereExample = (await manager.Where<Person>(x => x.Name.StartsWith("c", StringComparison.OrdinalIgnoreCase)
155-
// || x.Name.StartsWith("l", StringComparison.OrdinalIgnoreCase)
156-
// || x.Name.StartsWith("j", StringComparison.OrdinalIgnoreCase) && x._Age > 35
157-
// || x.Name.Contains("bo", StringComparison.OrdinalIgnoreCase)
158-
// //|| (x.DateOfBirth != null && x.DateOfBirth.GetValueOrDefault().Year < 1980)
159-
// || x.DateOfBirth == null
160-
// ).OrderBy(x => x._Id).Skip(1).ToListAsync());
154+
WhereExample = (await manager.Where<Person>(x => x.Name.StartsWith("c", StringComparison.OrdinalIgnoreCase)
155+
|| x.Name.StartsWith("l", StringComparison.OrdinalIgnoreCase)
156+
|| x.Name.StartsWith("j", StringComparison.OrdinalIgnoreCase) && x._Age > 35
157+
|| x.Name.Contains("bo", StringComparison.OrdinalIgnoreCase)
158+
//|| (x.DateOfBirth != null && x.DateOfBirth.GetValueOrDefault().Year < 1980)
159+
//|| x.DateOfBirth == null
160+
).OrderBy(x => x._Id).Skip(1).ToListAsync());
161+
162+
// WhereExample = (await manager.Where<Person>(x => x.DateOfBirth != null
163+
// ).ToListAsync());
164+
165+
// WhereExample = (await manager.Where<Person>(x => x.DateOfBirth != null
166+
// ).ToListAsync());
167+
168+
169+
// WhereExample = (await manager.Where<Person>(x => x.TestInt > 0
170+
// ).OrderBy(x => x._Id).Skip(1).Take(1).ToListAsync());
161171
162-
WhereExample = (await manager.Where<Person>(x => x.DateOfBirth == null
163-
).OrderBy(x => x._Id).Skip(1).Take(6).ToListAsync());
164172

165173
/*
166174
* Still working on allowing nested

0 commit comments

Comments
 (0)