Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed May 20, 2020
2 parents 537bb18 + 6cd44f7 commit b795baa
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Signum.Engine/Engine/Synchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public static void Synchronize<K, N, O>(

if (!oldExists)
{
createNew?.Invoke(key, newVal);
createNew?.Invoke(key, newVal!);
}
else if (!newExists)
{
removeOld?.Invoke(key, oldVal);
removeOld?.Invoke(key, oldVal!);
}
else
{
merge?.Invoke(key, newVal, oldVal);
merge?.Invoke(key, newVal!, oldVal!);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion Signum.Engine/Linq/AliasGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ internal Alias(ObjectName objectName)
this.ObjectName = objectName;
}

public bool Equals(Alias other)
public bool Equals(Alias? other)
{
if (other == null)
return false;

return this.Name == other.Name && object.Equals(this.ObjectName, other.ObjectName);
}

Expand Down
2 changes: 1 addition & 1 deletion Signum.Engine/Linq/DbExpressions.Sql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public override string ToString()
}

public override bool Equals(object? obj) => obj is ColumnExpression ce && Equals(ce);
public bool Equals(ColumnExpression other)
public bool Equals(ColumnExpression? other)
{
return other != null && other.Alias == Alias && other.Name == Name;
}
Expand Down
6 changes: 3 additions & 3 deletions Signum.Engine/Linq/ExpressionVisitor/DbExpressionComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected DbExpressionComparer(ScopedDictionary<ParameterExpression, ParameterEx
this.aliasMap = aliasScope;
}

public static bool AreEqual(Expression a, Expression b, ScopedDictionary<ParameterExpression, ParameterExpression>? parameterScope = null, ScopedDictionary<Alias, Alias>? aliasScope = null, bool checkParameterNames = false)
public static bool AreEqual(Expression? a, Expression? b, ScopedDictionary<ParameterExpression, ParameterExpression>? parameterScope = null, ScopedDictionary<Alias, Alias>? aliasScope = null, bool checkParameterNames = false)
{
return new DbExpressionComparer(parameterScope, aliasScope, checkParameterNames ).Compare(a, b);
}
Expand Down Expand Up @@ -169,7 +169,7 @@ protected virtual bool CompareAlias(Alias? a, Alias? b)

if (aliasMap != null)
{
if (aliasMap.TryGetValue(a, out Alias mapped))
if (aliasMap.TryGetValue(a, out Alias? mapped))
return mapped == b;
}
return a == b;
Expand Down Expand Up @@ -566,7 +566,7 @@ public DbExpressionsEqualityComparer(bool checkParameterNames)
this.checkParameterNames = checkParameterNames;
}

public bool Equals(E x, E y)
public bool Equals(E? x, E? y)
{
return DbExpressionComparer.AreEqual(x, y, checkParameterNames: this.checkParameterNames);
}
Expand Down
21 changes: 17 additions & 4 deletions Signum.Engine/Schema/ObjectName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ public override string ToString()
}

public override bool Equals(object? obj) => obj is ServerName sn && Equals(sn);
public bool Equals(ServerName other)
public bool Equals(ServerName? other)
{
if (other == null)
return false;

return other.Name == Name;
}

Expand Down Expand Up @@ -93,8 +96,11 @@ public override string ToString()


public override bool Equals(object? obj) => obj is DatabaseName dn && Equals(dn);
public bool Equals(DatabaseName other)
public bool Equals(DatabaseName? other)
{
if (other == null)
return false;

return other.Name == Name && object.Equals(Server, other.Server);
}

Expand Down Expand Up @@ -163,8 +169,12 @@ public override string ToString()
}

public override bool Equals(object? obj) => obj is SchemaName sn && Equals(sn);
public bool Equals(SchemaName other)
public bool Equals(SchemaName? other)
{

if (other == null)
return false;

return other.Name == Name &&
object.Equals(Database, other.Database);
}
Expand Down Expand Up @@ -218,8 +228,11 @@ public override string ToString()
}

public override bool Equals(object? obj) => obj is ObjectName on && Equals(on);
public bool Equals(ObjectName other)
public bool Equals(ObjectName? other)
{
if (other == null)
return false;

return other.Name == Name &&
object.Equals(Schema, other.Schema);
}
Expand Down
2 changes: 1 addition & 1 deletion Signum.Entities/DynamicQuery/Tokens/QueryToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public override bool Equals(object? obj)
return obj is QueryToken && obj.GetType() == this.GetType() && Equals((QueryToken)obj);
}

public bool Equals(QueryToken other)
public bool Equals(QueryToken? other)
{
return other != null && other.QueryName.Equals(this.QueryName) && other.FullKey() == this.FullKey();
}
Expand Down
7 changes: 5 additions & 2 deletions Signum.Entities/EnumEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ public override string ToString()
return Enum.IsDefined(typeof(T), en) ? en.ToString() : (this.toStr ?? en.ToString()); //for aux sync
}

public bool Equals(EnumEntity<T> other)
public bool Equals(EnumEntity<T>? other)
{
return EqualityComparer<T>.Default.Equals(ToEnum(), other.ToEnum());
if (other == null)
return false;

return EqualityComparer<T>.Default.Equals(ToEnum(), other!.ToEnum());
}

public static implicit operator EnumEntity<T>(T enumerable)
Expand Down
4 changes: 2 additions & 2 deletions Signum.Entities/Lite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ public string KeyLong()
return "{0};{1};{2}".FormatWith(TypeEntity.GetCleanName(this.EntityType), this.Id, this.ToString());
}

public int CompareTo(Lite<Entity> other)
public int CompareTo(Lite<Entity>? other)
{
return ToString()!.CompareTo(other.ToString());
return ToString()!.CompareTo(other?.ToString());
}

public int CompareTo(object? obj)
Expand Down
6 changes: 5 additions & 1 deletion Signum.Entities/PropertyRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,12 @@ public override int GetHashCode()
}

public override bool Equals(object? obj) => obj is PropertyRoute pr && Equals(pr);
public bool Equals(PropertyRoute other)
public bool Equals(PropertyRoute? other)
{

if (other==null)
return false;

if (other.PropertyRouteType != this.PropertyRouteType)
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections;
using Signum.Utilities.Reflection;
using Signum.Utilities;
using System.Diagnostics.CodeAnalysis;

namespace Signum.Entities.Reflection
{
Expand Down Expand Up @@ -42,7 +43,7 @@ public void Complete(IEqualityComparerResolver resolver, PropertyInfo? pi)
MixinDeclarations.GetMixinDeclarations(typeof(T)).ToDictionary(t => t, t => resolver.GetEqualityComparer(t, null));
}

public override bool Equals(T x, T y)
public override bool Equals(T? x, T? y)
{
if ((x == null) != (y == null))
return false;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void Complete(IEqualityComparerResolver resolver, PropertyInfo? pi)
comparer: resolver.GetEqualityComparer(((PropertyInfo)a.MemberInfo).PropertyType, (PropertyInfo)a.MemberInfo)));
}

public override bool Equals(T x, T y)
public override bool Equals([AllowNull] T x, [AllowNull] T y)
{
if ((x == null) != (y == null))
return false;
Expand Down Expand Up @@ -178,7 +179,7 @@ public void Complete(IEqualityComparerResolver resolver, PropertyInfo? pi)
ElementComparer = (IEqualityComparer<T>)resolver.GetEqualityComparer(typeof(T), pi);
}

public override bool Equals(IList<T> x, IList<T> y)
public override bool Equals(IList<T>? x, IList<T>? y)
{
if ((x == null) != (y == null))
return false;
Expand Down Expand Up @@ -224,7 +225,7 @@ public void Complete(IEqualityComparerResolver resolver, PropertyInfo? pi)
ElementComparer = (IEqualityComparer<T>)resolver.GetEqualityComparer(typeof(T), pi);
}

public override bool Equals(IList<T> mx, IList<T> my)
public override bool Equals(IList<T>? mx, IList<T>? my)
{
if ((mx == null) != (my == null))
return false;
Expand Down
8 changes: 7 additions & 1 deletion Signum.Utilities/DataStructures/HashsetComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ namespace Signum.Utilities.DataStructures
[Serializable]
public class HashSetComparer<T> : IEqualityComparer<HashSet<T>>, IEqualityComparer
{
public bool Equals(HashSet<T> x, HashSet<T> y)
public bool Equals(HashSet<T>? x, HashSet<T>? y)
{
if (x == null && y == null)
return true;

if (x == null || y == null)
return false;

return x.SetEquals(y);
}

Expand Down
42 changes: 38 additions & 4 deletions Signum.Utilities/DataStructures/LambdaComparer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections;
using System.Diagnostics.CodeAnalysis;

namespace Signum.Utilities.DataStructures
{
Expand All @@ -27,13 +28,30 @@ public LambdaComparer(Func<T, S> func, IEqualityComparer<S>? equalityComparer =
this.comparer = comparer ?? Comparer<S>.Default;
}

public int Compare(T x, T y)
public int Compare([AllowNull] T x, [AllowNull] T y)
{
if (x == null && y == null)
return 0;

if (x == null )
return -1;

if (y == null)
return 1;


return comparer.Compare(func(x), func(y));
}

public bool Equals(T x, T y)
public bool Equals([AllowNull] T x, [AllowNull] T y)
{
if (x == null && y == null)
return true;

if (x == null || y == null)
return false;


return equalityComparer.Equals(func(x), func(y));
}

Expand Down Expand Up @@ -86,8 +104,17 @@ public CombineComparer(IComparer<T> comparer1, IComparer<T> comparer2)
this.comparer2 = comparer2;
}

public int Compare(T x, T y)
public int Compare([AllowNull] T x, [AllowNull] T y)
{
if (x == null && y == null)
return 0;

if (x == null)
return -1;

if (y == null)
return 1;

return comparer1.Compare(x, y).DefaultToNull() ?? comparer2.Compare(x, y);
}

Expand All @@ -113,8 +140,15 @@ public CombineEqualityComparer(IEqualityComparer<T> comparer1, IEqualityComparer
this.comparer2 = comparer2;
}

public bool Equals(T x, T y)
public bool Equals([AllowNull] T x, [AllowNull] T y)
{

if (x == null && y == null)
return true;

if (x == null || y == null)
return false;

return comparer1.Equals(x, y) && comparer2.Equals(x,y);
}

Expand Down
3 changes: 2 additions & 1 deletion Signum.Utilities/DataStructures/ReferenceEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Collections;
using System.Diagnostics.CodeAnalysis;

namespace Signum.Utilities.DataStructures
{
Expand All @@ -23,7 +24,7 @@ public int GetHashCode(T item)
return RuntimeHelpers.GetHashCode(item);
}

public bool Equals(T x, T y)
public bool Equals([AllowNull] T x, [AllowNull] T y)
{
return object.ReferenceEquals(x, y);
}
Expand Down
3 changes: 2 additions & 1 deletion Signum.Utilities/DataStructures/ScopedDictionary.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Signum.Utilities.DataStructures
{
Expand Down Expand Up @@ -30,7 +31,7 @@ public void Add(TKey key, TValue value)
this.map.Add(key, value);
}

public bool TryGetValue(TKey key, out TValue value)
public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
{
for (ScopedDictionary<TKey, TValue>? scope = this; scope != null; scope = scope.previous)
{
Expand Down
4 changes: 2 additions & 2 deletions Signum.Utilities/ExpressionTrees/ExpressionComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected virtual bool CompareParameter(ParameterExpression a, ParameterExpressi
{
if (parameterScope != null)
{
if (parameterScope.TryGetValue(a, out ParameterExpression mapped))
if (parameterScope.TryGetValue(a, out ParameterExpression? mapped))
return mapped == b;
}
return a == b;
Expand Down Expand Up @@ -322,7 +322,7 @@ public ExpressionsEqualityComparer(bool checkParameterNames)
this.checkParameterNames = checkParameterNames;
}

public bool Equals(E x, E y)
public bool Equals(E? x, E? y)
{
return ExpressionComparer.AreEqual(x, y, parameterScope: null, checkParameterNames: checkParameterNames);
}
Expand Down
8 changes: 7 additions & 1 deletion Signum.Utilities/Reflection/GenericInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ public T GetInvoker(params Type[] types)
class TypeArrayEqualityComparer : IEqualityComparer<Type[]>
{
public static readonly TypeArrayEqualityComparer Instance = new TypeArrayEqualityComparer();
public bool Equals(Type[] x, Type[] y)
public bool Equals(Type[]? x, Type[]? y)
{
if (x == null && y == null)
return true;

if (x == null || y == null)
return false;

for (int i = 0; i < x.Length; i++)
{
if (!x[i].Equals(y[i]))
Expand Down

0 comments on commit b795baa

Please sign in to comment.