Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm.Tests/Rse/HeaderParseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void MainTest()
ResetState(state);

// Select Id, TypeId, Title
CompilableProvider rsTitle = rsMain.Select(0, 1, 2);
CompilableProvider rsTitle = rsMain.Select(new[] { 0, 1, 2 });
UpdateCache(session, rsTitle.GetRecordSetReader(session, parameterContext));
state = Session.Current.EntityStateCache[key, true];
Assert.IsNotNull(state);
Expand All @@ -63,7 +63,7 @@ public void MainTest()
ResetState(state);

// Select Id, TypeId, Text
CompilableProvider rsText = rsMain.Select(0, 1, 3);
CompilableProvider rsText = rsMain.Select(new[] { 0, 1, 3 });
UpdateCache(session, rsText.GetRecordSetReader(session, parameterContext));
state = Session.Current.EntityStateCache[key, true];
Assert.IsNotNull(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void SelectCharTest()
var rs = GetRseQuery<MyEntity>();
var parameterContext = new ParameterContext();
var result = rs
.Select(rs.Header.IndexOf(charColumn))
.Select(new[] { rs.Header.IndexOf(charColumn) })
.GetRecordSetReader(Session.Current, parameterContext)
.ToEnumerable()
.Select(i => i.GetValueOrDefault<char>(0))
Expand All @@ -88,7 +88,7 @@ public void CharParameterTest()
var rs = GetRseQuery<MyEntity>();
var parameterContext = new ParameterContext();
var result = rs
.Select(rs.Header.IndexOf(charColumn))
.Select(new[] { rs.Header.IndexOf(charColumn) })
.Filter(t => t.GetValueOrDefault<char>(0) == y)
.GetRecordSetReader(Session.Current, parameterContext)
.ToEnumerable()
Expand All @@ -108,7 +108,7 @@ public void CharConstantTest()
var rs = GetRseQuery<MyEntity>();
var parameterContext = new ParameterContext();
var result = rs
.Select(rs.Header.IndexOf(charColumn))
.Select(new[] { rs.Header.IndexOf(charColumn) })
.Filter(t => t.GetValueOrDefault<char>(0)=='Y')
.GetRecordSetReader(Session.Current, parameterContext)
.ToEnumerable()
Expand Down
10 changes: 2 additions & 8 deletions Orm/Xtensive.Orm/Arithmetic/ArithmeticRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,8 @@ public bool Equals(ArithmeticRules other)
}

/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj==null)
return false;
if (obj is ArithmeticRules)
return Equals((ArithmeticRules)obj);
return false;
}
public override bool Equals(object obj) =>
obj is ArithmeticRules other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down
33 changes: 12 additions & 21 deletions Orm/Xtensive.Orm/Caching/WeakestCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,24 @@ internal sealed class WeakEntryEqualityComparer : IEqualityComparer<object>

public new bool Equals(object x, object y)
{
TKey key;
var we = x as WeakEntry;
if (we!=null) {
if (x is WeakEntry we) {
// x is WeakEntry
key = y as TKey;
if (key!=null)
if (y is TKey key)
// x is WeakEntry, y is TKey
return keyComparer.Equals(we.Key, key);
else {
var we2 = y as WeakEntry;
if (we2==null)
return false;
// x is WeakEntry, y is WeakEntry
return keyComparer.Equals(we.Key, we2.Key);
return y is WeakEntry we2 && keyComparer.Equals(we.Key, we2.Key); // x is WeakEntry, y is WeakEntry
}
}
key = x as TKey;
if (key==null)
return false;
// x is TKey
we = y as WeakEntry;
if (we!=null)
// x is TKey, y is WeakEntry
return keyComparer.Equals(key, we.Key);
else
// x is TKey, y must be TKey
return keyComparer.Equals(key, y as TKey);
if (x is TKey keyX) {
if (y is WeakEntry weY)
// x is TKey, y is WeakEntry
return keyComparer.Equals(keyX, weY.Key);
else
// x is TKey, y must be TKey
return keyComparer.Equals(keyX, y as TKey);
}
return false;
}

public int GetHashCode(object obj)
Expand Down
8 changes: 2 additions & 6 deletions Orm/Xtensive.Orm/Comparison/ComparisonRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,8 @@ public bool Equals(ComparisonRule other)
}

/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj is ComparisonRule)
return Equals((ComparisonRule)obj);
return false;
}
public override bool Equals(object obj) =>
obj is ComparisonRule other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down
8 changes: 2 additions & 6 deletions Orm/Xtensive.Orm/Comparison/ComparisonRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,8 @@ public bool Equals(ComparisonRules other)
#region Equals, GetHashCode

/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj is ComparisonRules)
return Equals((ComparisonRules)obj);
return false;
}
public override bool Equals(object obj) =>
obj is ComparisonRules other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down
8 changes: 2 additions & 6 deletions Orm/Xtensive.Orm/Conversion/Biconverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ public bool Equals(Biconverter<TFrom, TTo> obj)
}

/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj.GetType()!=typeof (Biconverter<TFrom, TTo>))
return false;
return Equals((Biconverter<TFrom, TTo>) obj);
}
public override bool Equals(object obj) =>
obj is Biconverter<TFrom, TTo> other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down
8 changes: 2 additions & 6 deletions Orm/Xtensive.Orm/Core/HasVersion{TValue,TVersion}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ public int CompareTo(HasVersion<TValue, TVersion> other)
#region Equals, GetHashCode, ==, !=

/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj.GetType()!=typeof (HasVersion<TValue, TVersion>))
return false;
return Equals((HasVersion<TValue, TVersion>) obj);
}
public override bool Equals(object obj) =>
obj is HasVersion<TValue, TVersion> other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down
27 changes: 11 additions & 16 deletions Orm/Xtensive.Orm/Core/Pair{TFirst,TSecond}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace Xtensive.Core
IComparable<Pair<TFirst, TSecond>>,
IEquatable<Pair<TFirst, TSecond>>
{
private static readonly AdvancedComparerStruct<TFirst> FirstComparer = AdvancedComparerStruct<TFirst>.System;
private static readonly AdvancedComparerStruct<TSecond> SecondComparer = AdvancedComparerStruct<TSecond>.System;

/// <summary>
/// A first value.
/// </summary>
Expand All @@ -33,33 +36,25 @@ namespace Xtensive.Core
#region IComparable<...>, IEquatable<...> methods

/// <inheritdoc/>
public bool Equals(Pair<TFirst, TSecond> other)
{
if (!AdvancedComparerStruct<TFirst>.System.Equals(First, other.First))
return false;
return AdvancedComparerStruct<TSecond>.System.Equals(Second, other.Second);
}
public bool Equals(Pair<TFirst, TSecond> other) =>
FirstComparer.Equals(First, other.First) && SecondComparer.Equals(Second, other.Second);

/// <inheritdoc/>
public int CompareTo(Pair<TFirst, TSecond> other)
{
int result = AdvancedComparerStruct<TFirst>.System.Compare(First, other.First);
if (result != 0)
return result;
return AdvancedComparerStruct<TSecond>.System.Compare(Second, other.Second);
int result = FirstComparer.Compare(First, other.First);
return result != 0
? result
: SecondComparer.Compare(Second, other.Second);
}

#endregion

#region Equals, GetHashCode, ==, !=

/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj.GetType() != typeof(Pair<TFirst, TSecond>))
return false;
return Equals((Pair<TFirst, TSecond>) obj);
}
public override bool Equals(object obj) =>
obj is Pair<TFirst, TSecond> other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down
28 changes: 11 additions & 17 deletions Orm/Xtensive.Orm/Core/Pair{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Xtensive.Core
IEquatable<Pair<T>>,
IComparable<Pair<T>>
{
private static readonly AdvancedComparerStruct<T> Comparer = AdvancedComparerStruct<T>.System;

/// <summary>
/// The first value.
/// </summary>
Expand All @@ -35,33 +37,25 @@ namespace Xtensive.Core
#region IComparable<...>, IEquatable<...> methods

/// <inheritdoc/>
public bool Equals(Pair<T> other)
{
if (!AdvancedComparerStruct<T>.System.Equals(First, other.First))
return false;
return AdvancedComparerStruct<T>.System.Equals(Second, other.Second);
}
public bool Equals(Pair<T> other) =>
Comparer.Equals(First, other.First) && Comparer.Equals(Second, other.Second);

/// <inheritdoc/>
public int CompareTo(Pair<T> other)
{
int result = AdvancedComparerStruct<T>.System.Compare(First, other.First);
if (result!=0)
return result;
return AdvancedComparerStruct<T>.System.Compare(Second, other.Second);
int result = Comparer.Compare(First, other.First);
return result != 0
? result
: Comparer.Compare(Second, other.Second);
}

#endregion

#region Equals, GetHashCode, ==, !=

/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj.GetType()!=typeof (Pair<T>))
return false;
return Equals((Pair<T>) obj);
}
public override bool Equals(object obj) =>
obj is Pair<T> other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down Expand Up @@ -117,4 +111,4 @@ public Pair(T first, T second)
Second = second;
}
}
}
}
10 changes: 2 additions & 8 deletions Orm/Xtensive.Orm/Core/Segment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,8 @@ public int CompareTo(Pair<T> other)
#region Equals, GetHashCode

/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj is Pair<T>) {
Pair<T> other = (Pair<T>)obj;
return Equals(other);
}
return false;
}
public override bool Equals(object obj) =>
obj is Pair<T> other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,12 @@ private Expression VisitParameter(SerializableParameterExpression p)
private Expression VisitMemberAccess(SerializableMemberExpression m)
{
var target = Visit(m.Expression);
var field = m.Member as FieldInfo;
if (field != null)
return Expression.Field(target, field);
var property = m.Member as PropertyInfo;
if (property != null)
return Expression.Property(target, property);
var method = m.Member as MethodInfo;
if (method != null)
return Expression.Property(target, method);
throw new ArgumentException();
return m.Member switch {
FieldInfo field => Expression.Field(target, field),
PropertyInfo property => Expression.Property(target, property),
MethodInfo method => Expression.Property(target, method),
_ => throw new ArgumentException()
};
}

private Expression VisitMethodCall(SerializableMethodCallExpression mc)
Expand Down
2 changes: 1 addition & 1 deletion Orm/Xtensive.Orm/Modelling/Comparison/Comparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected virtual Difference VisitNode(Node source, Node target)
if ((difference.MovementInfo & recreated) != recreated) {
var propertyAccessors = difference.PropertyChanges
.Where(p => p.Value.Source != null && p.Value.Target != null)
.Select(p => new {Pair = p, NodeDifference = p.Value as NodeDifference})
.Select(p => (Pair: p, NodeDifference: p.Value as NodeDifference))
.Where(a => a.NodeDifference != null && !a.NodeDifference.IsNameChanged)
.Select(a => source.PropertyAccessors[a.Pair.Key])
.ToList();
Expand Down
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm/Modelling/Comparison/Upgrader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,12 @@ protected static string GetPathWithoutName(Node node)
/// <returns>A disposable deactivating the group.</returns>
protected IDisposable OpenActionGroup(string comment)
{
var oldActions = new {
var oldActions = (
Context.PreConditions,
Context.Actions,
Context.Renames,
Context.PostConditions
};
);
Context.PreConditions = new GroupingNodeAction {
Comment = PreConditionsGroupComment
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ public bool Equals(DatabaseReference other)
return string.Equals(TargetDatabase, other.TargetDatabase) && string.Equals(OwnerDatabase, other.OwnerDatabase);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
return false;
return obj is DatabaseReference && Equals((DatabaseReference) obj);
}
public override bool Equals(object obj) =>
obj is DatabaseReference other && Equals(other);

public override int GetHashCode()
{
Expand Down
Loading