diff --git a/Orm/Xtensive.Orm.Tests/Rse/HeaderParseTest.cs b/Orm/Xtensive.Orm.Tests/Rse/HeaderParseTest.cs index bcf7351219..85dfa418d1 100644 --- a/Orm/Xtensive.Orm.Tests/Rse/HeaderParseTest.cs +++ b/Orm/Xtensive.Orm.Tests/Rse/HeaderParseTest.cs @@ -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); @@ -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); diff --git a/Orm/Xtensive.Orm.Tests/Storage/Providers/Sql/CharSupportTest.cs b/Orm/Xtensive.Orm.Tests/Storage/Providers/Sql/CharSupportTest.cs index c67c441930..9103bbf4c1 100644 --- a/Orm/Xtensive.Orm.Tests/Storage/Providers/Sql/CharSupportTest.cs +++ b/Orm/Xtensive.Orm.Tests/Storage/Providers/Sql/CharSupportTest.cs @@ -66,7 +66,7 @@ public void SelectCharTest() var rs = GetRseQuery(); 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(0)) @@ -88,7 +88,7 @@ public void CharParameterTest() var rs = GetRseQuery(); var parameterContext = new ParameterContext(); var result = rs - .Select(rs.Header.IndexOf(charColumn)) + .Select(new[] { rs.Header.IndexOf(charColumn) }) .Filter(t => t.GetValueOrDefault(0) == y) .GetRecordSetReader(Session.Current, parameterContext) .ToEnumerable() @@ -108,7 +108,7 @@ public void CharConstantTest() var rs = GetRseQuery(); var parameterContext = new ParameterContext(); var result = rs - .Select(rs.Header.IndexOf(charColumn)) + .Select(new[] { rs.Header.IndexOf(charColumn) }) .Filter(t => t.GetValueOrDefault(0)=='Y') .GetRecordSetReader(Session.Current, parameterContext) .ToEnumerable() diff --git a/Orm/Xtensive.Orm/Arithmetic/ArithmeticRules.cs b/Orm/Xtensive.Orm/Arithmetic/ArithmeticRules.cs index 61cb801450..020f3759ca 100644 --- a/Orm/Xtensive.Orm/Arithmetic/ArithmeticRules.cs +++ b/Orm/Xtensive.Orm/Arithmetic/ArithmeticRules.cs @@ -41,14 +41,8 @@ public bool Equals(ArithmeticRules other) } /// - 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); /// public override int GetHashCode() diff --git a/Orm/Xtensive.Orm/Caching/WeakestCache.cs b/Orm/Xtensive.Orm/Caching/WeakestCache.cs index 1140b1c814..51e2d181f7 100644 --- a/Orm/Xtensive.Orm/Caching/WeakestCache.cs +++ b/Orm/Xtensive.Orm/Caching/WeakestCache.cs @@ -131,33 +131,24 @@ internal sealed class WeakEntryEqualityComparer : IEqualityComparer 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) diff --git a/Orm/Xtensive.Orm/Comparison/ComparisonRule.cs b/Orm/Xtensive.Orm/Comparison/ComparisonRule.cs index 85d779da9b..cddce92fa6 100644 --- a/Orm/Xtensive.Orm/Comparison/ComparisonRule.cs +++ b/Orm/Xtensive.Orm/Comparison/ComparisonRule.cs @@ -83,12 +83,8 @@ public bool Equals(ComparisonRule other) } /// - 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); /// public override int GetHashCode() diff --git a/Orm/Xtensive.Orm/Comparison/ComparisonRules.cs b/Orm/Xtensive.Orm/Comparison/ComparisonRules.cs index 59a1222afb..f72e43309f 100644 --- a/Orm/Xtensive.Orm/Comparison/ComparisonRules.cs +++ b/Orm/Xtensive.Orm/Comparison/ComparisonRules.cs @@ -193,12 +193,8 @@ public bool Equals(ComparisonRules other) #region Equals, GetHashCode /// - 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); /// public override int GetHashCode() diff --git a/Orm/Xtensive.Orm/Conversion/Biconverter.cs b/Orm/Xtensive.Orm/Conversion/Biconverter.cs index 30ec65a636..174512e7d1 100644 --- a/Orm/Xtensive.Orm/Conversion/Biconverter.cs +++ b/Orm/Xtensive.Orm/Conversion/Biconverter.cs @@ -53,12 +53,8 @@ public bool Equals(Biconverter obj) } /// - public override bool Equals(object obj) - { - if (obj.GetType()!=typeof (Biconverter)) - return false; - return Equals((Biconverter) obj); - } + public override bool Equals(object obj) => + obj is Biconverter other && Equals(other); /// public override int GetHashCode() diff --git a/Orm/Xtensive.Orm/Core/HasVersion{TValue,TVersion}.cs b/Orm/Xtensive.Orm/Core/HasVersion{TValue,TVersion}.cs index d21e0af5e2..630107db85 100644 --- a/Orm/Xtensive.Orm/Core/HasVersion{TValue,TVersion}.cs +++ b/Orm/Xtensive.Orm/Core/HasVersion{TValue,TVersion}.cs @@ -57,12 +57,8 @@ public int CompareTo(HasVersion other) #region Equals, GetHashCode, ==, != /// - public override bool Equals(object obj) - { - if (obj.GetType()!=typeof (HasVersion)) - return false; - return Equals((HasVersion) obj); - } + public override bool Equals(object obj) => + obj is HasVersion other && Equals(other); /// public override int GetHashCode() diff --git a/Orm/Xtensive.Orm/Core/Pair{TFirst,TSecond}.cs b/Orm/Xtensive.Orm/Core/Pair{TFirst,TSecond}.cs index 3a447cfd87..af240475fb 100644 --- a/Orm/Xtensive.Orm/Core/Pair{TFirst,TSecond}.cs +++ b/Orm/Xtensive.Orm/Core/Pair{TFirst,TSecond}.cs @@ -21,6 +21,9 @@ namespace Xtensive.Core IComparable>, IEquatable> { + private static readonly AdvancedComparerStruct FirstComparer = AdvancedComparerStruct.System; + private static readonly AdvancedComparerStruct SecondComparer = AdvancedComparerStruct.System; + /// /// A first value. /// @@ -33,20 +36,16 @@ namespace Xtensive.Core #region IComparable<...>, IEquatable<...> methods /// - public bool Equals(Pair other) - { - if (!AdvancedComparerStruct.System.Equals(First, other.First)) - return false; - return AdvancedComparerStruct.System.Equals(Second, other.Second); - } + public bool Equals(Pair other) => + FirstComparer.Equals(First, other.First) && SecondComparer.Equals(Second, other.Second); /// public int CompareTo(Pair other) { - int result = AdvancedComparerStruct.System.Compare(First, other.First); - if (result != 0) - return result; - return AdvancedComparerStruct.System.Compare(Second, other.Second); + int result = FirstComparer.Compare(First, other.First); + return result != 0 + ? result + : SecondComparer.Compare(Second, other.Second); } #endregion @@ -54,12 +53,8 @@ public int CompareTo(Pair other) #region Equals, GetHashCode, ==, != /// - public override bool Equals(object obj) - { - if (obj.GetType() != typeof(Pair)) - return false; - return Equals((Pair) obj); - } + public override bool Equals(object obj) => + obj is Pair other && Equals(other); /// public override int GetHashCode() diff --git a/Orm/Xtensive.Orm/Core/Pair{T}.cs b/Orm/Xtensive.Orm/Core/Pair{T}.cs index b4c56744b3..96a40c8524 100644 --- a/Orm/Xtensive.Orm/Core/Pair{T}.cs +++ b/Orm/Xtensive.Orm/Core/Pair{T}.cs @@ -22,6 +22,8 @@ namespace Xtensive.Core IEquatable>, IComparable> { + private static readonly AdvancedComparerStruct Comparer = AdvancedComparerStruct.System; + /// /// The first value. /// @@ -35,20 +37,16 @@ namespace Xtensive.Core #region IComparable<...>, IEquatable<...> methods /// - public bool Equals(Pair other) - { - if (!AdvancedComparerStruct.System.Equals(First, other.First)) - return false; - return AdvancedComparerStruct.System.Equals(Second, other.Second); - } + public bool Equals(Pair other) => + Comparer.Equals(First, other.First) && Comparer.Equals(Second, other.Second); /// public int CompareTo(Pair other) { - int result = AdvancedComparerStruct.System.Compare(First, other.First); - if (result!=0) - return result; - return AdvancedComparerStruct.System.Compare(Second, other.Second); + int result = Comparer.Compare(First, other.First); + return result != 0 + ? result + : Comparer.Compare(Second, other.Second); } #endregion @@ -56,12 +54,8 @@ public int CompareTo(Pair other) #region Equals, GetHashCode, ==, != /// - public override bool Equals(object obj) - { - if (obj.GetType()!=typeof (Pair)) - return false; - return Equals((Pair) obj); - } + public override bool Equals(object obj) => + obj is Pair other && Equals(other); /// public override int GetHashCode() @@ -117,4 +111,4 @@ public Pair(T first, T second) Second = second; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Core/Segment.cs b/Orm/Xtensive.Orm/Core/Segment.cs index 98d43c6820..a04902dcd6 100644 --- a/Orm/Xtensive.Orm/Core/Segment.cs +++ b/Orm/Xtensive.Orm/Core/Segment.cs @@ -62,14 +62,8 @@ public int CompareTo(Pair other) #region Equals, GetHashCode /// - public override bool Equals(object obj) - { - if (obj is Pair) { - Pair other = (Pair)obj; - return Equals(other); - } - return false; - } + public override bool Equals(object obj) => + obj is Pair other && Equals(other); /// public override int GetHashCode() diff --git a/Orm/Xtensive.Orm/Linq/SerializableExpressions/Internals/SerializableExpressionToExpressionConverter.cs b/Orm/Xtensive.Orm/Linq/SerializableExpressions/Internals/SerializableExpressionToExpressionConverter.cs index 4dd758ac98..06c5ce318b 100644 --- a/Orm/Xtensive.Orm/Linq/SerializableExpressions/Internals/SerializableExpressionToExpressionConverter.cs +++ b/Orm/Xtensive.Orm/Linq/SerializableExpressions/Internals/SerializableExpressionToExpressionConverter.cs @@ -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) diff --git a/Orm/Xtensive.Orm/Modelling/Comparison/Comparer.cs b/Orm/Xtensive.Orm/Modelling/Comparison/Comparer.cs index 3e63fdc69f..6ff38cc2ee 100644 --- a/Orm/Xtensive.Orm/Modelling/Comparison/Comparer.cs +++ b/Orm/Xtensive.Orm/Modelling/Comparison/Comparer.cs @@ -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(); diff --git a/Orm/Xtensive.Orm/Modelling/Comparison/Upgrader.cs b/Orm/Xtensive.Orm/Modelling/Comparison/Upgrader.cs index 00dc5305aa..f28483808f 100644 --- a/Orm/Xtensive.Orm/Modelling/Comparison/Upgrader.cs +++ b/Orm/Xtensive.Orm/Modelling/Comparison/Upgrader.cs @@ -657,12 +657,12 @@ protected static string GetPathWithoutName(Node node) /// A disposable deactivating the group. protected IDisposable OpenActionGroup(string comment) { - var oldActions = new { + var oldActions = ( Context.PreConditions, Context.Actions, Context.Renames, Context.PostConditions - }; + ); Context.PreConditions = new GroupingNodeAction { Comment = PreConditionsGroupComment }; diff --git a/Orm/Xtensive.Orm/Orm/Building/Builders/DatabaseDependencyBuilder.cs b/Orm/Xtensive.Orm/Orm/Building/Builders/DatabaseDependencyBuilder.cs index c060721f9f..7a8b1b409b 100644 --- a/Orm/Xtensive.Orm/Orm/Building/Builders/DatabaseDependencyBuilder.cs +++ b/Orm/Xtensive.Orm/Orm/Building/Builders/DatabaseDependencyBuilder.cs @@ -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() { diff --git a/Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.cs b/Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.cs index a787c1a07d..60746fcf09 100644 --- a/Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.cs +++ b/Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.cs @@ -192,7 +192,7 @@ private void BuildInterfaceIndexes() .Where(t => t.Hierarchy == grouping.Key && !t.IsAbstract) .ToList(); var primaryIndexes = allImplementors - .Select(t => new {Index = t.Indexes.Single(i => i.IsPrimary && !i.IsVirtual), Type = t}) + .Select(t => (Index: t.Indexes.Single(i => i.IsPrimary && !i.IsVirtual), Type: t)) .Select(p => untypedIndexes.Contains(p.Index) ? p.Type.Indexes.Single(i => i.IsPrimary && i.IsTyped) : p.Index) @@ -260,7 +260,7 @@ private void BuildInterfaceIndexes() case InheritanceSchema.ConcreteTable: { var indexes = @interface.GetImplementors(true) .Where(t => t.Hierarchy == grouping.Key) - .Select(t => new { Index = t.Indexes.Single(i => i.DeclaringIndex == localIndex.DeclaringIndex && !i.IsVirtual), Type = t }) + .Select(t => (Index: t.Indexes.Single(i => i.DeclaringIndex == localIndex.DeclaringIndex && !i.IsVirtual), Type: t)) .Select(p => untypedIndexes.Contains(p.Index) ? p.Type.Indexes.Single(i => i.DeclaringIndex == localIndex.DeclaringIndex && i.IsTyped) : p.Index); @@ -377,7 +377,7 @@ private IndexInfo BuildIndex(TypeInfo typeInfo, IndexDef indexDef, bool buildAbs // There might be difference in columns order of type and columns list // so we have to reorder them in correct sequence. if (typeInfo.IsInterface) { - var indexedColumns = columns.Select((column, i) => new { i, j = typeInfo.Columns.IndexOf(column), column }).ToList(); + var indexedColumns = columns.Select((column, i) => (i, j: typeInfo.Columns.IndexOf(column), column)).ToList(); var orderedColumns = indexedColumns.OrderBy(el => el.j).Select(el => el.column).Distinct(); result.ValueColumns.AddRange(GatherValueColumns(orderedColumns)); } @@ -592,7 +592,7 @@ private IndexInfo BuildJoinIndex(TypeInfo reflectedType, IEnumerable // Adding value columns var typeOrder = reflectedType.GetAncestors() .Append(reflectedType) - .Select((t, i) => new {Type = t, Index = i}) + .Select((t, i) => (Type: t, Index: i)) .ToDictionary(a => a.Type, a => a.Index); var types = reflectedType.GetAncestors().ToHashSet(); types.Add(reflectedType); @@ -627,7 +627,7 @@ private IndexInfo BuildJoinIndex(TypeInfo reflectedType, IEnumerable valueColumnMap.Add(columnMap); } var orderedIndexes = indexesToJoin - .Select((index, i) => new {index, columns = valueColumnMap[i], i}) + .Select((index, i) => (index, columns: valueColumnMap[i], i)) .OrderBy(a => typeOrder[a.index.ValueColumns.First().Field.ReflectedType]) .ToList(); @@ -758,7 +758,7 @@ private IndexInfo BuildViewIndex(TypeInfo reflectedType, IndexInfo indexToApplyV columnMap.Add(keyLength + i); } var actualColumnMapping = valueColumns - .Zip(columnMap, (column, sourceIndex) => new {column, sourceIndex}) + .Zip(columnMap, (column, sourceIndex) => (column, sourceIndex)) .OrderBy(p => reflectedType.Columns.IndexOf(p.column)) .ToList(); valueColumns.Clear(); @@ -814,7 +814,7 @@ private ColumnGroup BuildColumnGroup(IndexInfo index) : index.KeyColumns .Select(pair => pair.Key) .Concat(index.ValueColumns) - .Select((c, i) => new {c, i}) + .Select((c, i) => (c, i)) .Where(arg => arg.c.IsPrimaryKey) .Select(arg => arg.i) .ToList(); diff --git a/Orm/Xtensive.Orm/Orm/Building/Builders/MemberCompilerProviderBuilder.cs b/Orm/Xtensive.Orm/Orm/Building/Builders/MemberCompilerProviderBuilder.cs index ff5de52a14..910dddd047 100644 --- a/Orm/Xtensive.Orm/Orm/Building/Builders/MemberCompilerProviderBuilder.cs +++ b/Orm/Xtensive.Orm/Orm/Building/Builders/MemberCompilerProviderBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2011-2020 Xtensive LLC. +// Copyright (C) 2011-2020 Xtensive LLC. // This code is distributed under MIT license terms. // See the License.txt file in the project root for more information. // Created by: Denis Krjuchkov @@ -56,10 +56,10 @@ private void RegisterLinqExtensions() private void RegisterContainers(IEnumerable containers) { var groupings = containers - .Select(container => new { - Container = container, - Attribute = GetCompilerContainerAttribute(container) - }) + .Select(container => ( + Container: container, + Attribute: GetCompilerContainerAttribute(container) + )) .GroupBy(item => item.Attribute.TargetType); foreach (var grouping in groupings) { diff --git a/Orm/Xtensive.Orm/Orm/Building/Builders/ProviderDescriptor.cs b/Orm/Xtensive.Orm/Orm/Building/Builders/ProviderDescriptor.cs index e8f62107c4..01d59339a5 100644 --- a/Orm/Xtensive.Orm/Orm/Building/Builders/ProviderDescriptor.cs +++ b/Orm/Xtensive.Orm/Orm/Building/Builders/ProviderDescriptor.cs @@ -41,10 +41,10 @@ public static ProviderDescriptor Get(string providerName) var entry = providerAssembly.GetTypes() .Where(type => type.IsPublicNonAbstractInheritorOf(typeof (HandlerFactory))) .Where(type => type.IsDefined(typeof (ProviderAttribute), false)) - .Select(type => new {HandlerFactory = type, Attribute = type.GetAttribute()}) - .SingleOrDefault(e => e.Attribute.Name==providerName); + .Select(type => (HandlerFactory: type, Attribute: type.GetAttribute())) + .SingleOrDefault(e => e.Attribute.Name == providerName); - if (entry==null) + if (entry == default) throw new DomainBuilderException(string.Format( Strings.ExStorageProviderXIsNotFound, providerName)); diff --git a/Orm/Xtensive.Orm/Orm/Building/Builders/StorageMappingBuilder.cs b/Orm/Xtensive.Orm/Orm/Building/Builders/StorageMappingBuilder.cs index 9a8ac7cdce..9087473080 100644 --- a/Orm/Xtensive.Orm/Orm/Building/Builders/StorageMappingBuilder.cs +++ b/Orm/Xtensive.Orm/Orm/Building/Builders/StorageMappingBuilder.cs @@ -28,12 +28,8 @@ public bool Equals(MappingRequest other) return Equals(Assembly, other.Assembly) && string.Equals(Namespace, other.Namespace, StringComparison.Ordinal); } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - return false; - return obj is MappingRequest && Equals((MappingRequest) obj); - } + public override bool Equals(object obj) => + obj is MappingRequest other && Equals(other); public override int GetHashCode() { diff --git a/Orm/Xtensive.Orm/Orm/Building/Builders/TypeBuilder.cs b/Orm/Xtensive.Orm/Orm/Building/Builders/TypeBuilder.cs index cab2a1ba1f..c5b7515c88 100644 --- a/Orm/Xtensive.Orm/Orm/Building/Builders/TypeBuilder.cs +++ b/Orm/Xtensive.Orm/Orm/Building/Builders/TypeBuilder.cs @@ -296,13 +296,13 @@ private FieldInfo BuildDeclaredField(TypeInfo type, FieldDef fieldDef) } currentIndex.Fields.AddRange(structureFullTextIndex.Fields - .Select(f => new { + .Select(f => ( fieldInfo.DeclaringType .StructureFieldMapping[new Pair(fieldInfo, structureTypeInfo.Fields[f.Name])].Name, f.IsAnalyzed, f.Configuration, f.TypeFieldName - }) + )) .Select(g => new FullTextFieldDef(g.Name, g.IsAnalyzed) { Configuration = g.Configuration, TypeFieldName = g.TypeFieldName })); diff --git a/Orm/Xtensive.Orm/Orm/Building/DependencyGraph/Edge.cs b/Orm/Xtensive.Orm/Orm/Building/DependencyGraph/Edge.cs index c89cb21245..5f57977d95 100644 --- a/Orm/Xtensive.Orm/Orm/Building/DependencyGraph/Edge.cs +++ b/Orm/Xtensive.Orm/Orm/Building/DependencyGraph/Edge.cs @@ -9,7 +9,7 @@ namespace Xtensive.Orm.Building.DependencyGraph { [Serializable] - internal class Edge + internal sealed class Edge { public Node Tail { get; private set; } @@ -38,16 +38,9 @@ public bool Equals(Edge obj) } /// - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - return false; - if (ReferenceEquals(this, obj)) - return true; - if (obj.GetType()!=typeof (Edge)) - return false; - return Equals((Edge) obj); - } + public override bool Equals(object obj) => + ReferenceEquals(this, obj) + || obj is Edge other && Equals(other); /// public static bool operator ==(Edge left, Edge right) diff --git a/Orm/Xtensive.Orm/Orm/Configuration/SessionConfigurationCollection.cs b/Orm/Xtensive.Orm/Orm/Configuration/SessionConfigurationCollection.cs index 3befdc65e0..82f7428876 100644 --- a/Orm/Xtensive.Orm/Orm/Configuration/SessionConfigurationCollection.cs +++ b/Orm/Xtensive.Orm/Orm/Configuration/SessionConfigurationCollection.cs @@ -97,17 +97,9 @@ private void EnsureItemIsValid(SessionConfiguration item) #region Equality members /// - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - return false; - if (ReferenceEquals(this, obj)) - return true; - var scc = obj as SessionConfigurationCollection; - if (scc == null) - return false; - return Equals(scc); - } + public override bool Equals(object obj) => + ReferenceEquals(this, obj) + || obj is SessionConfigurationCollection other && Equals(other); /// public bool Equals(SessionConfigurationCollection obj) diff --git a/Orm/Xtensive.Orm/Orm/Entity.cs b/Orm/Xtensive.Orm/Orm/Entity.cs index 5e4bcf4fda..1c301594da 100644 --- a/Orm/Xtensive.Orm/Orm/Entity.cs +++ b/Orm/Xtensive.Orm/Orm/Entity.cs @@ -50,7 +50,7 @@ namespace Xtensive.Orm /// { /// [Field, Key] /// public int Id { get; set; } - /// + /// /// [Field] /// public string Name { get; set; } /// } @@ -234,7 +234,7 @@ public override sealed event PropertyChangedEventHandler PropertyChanged Key, EntityEventBroker.PropertyChangedEventKey, value); } remove { - Session.EntityEvents.RemoveSubscriber(Key, + Session.EntityEvents.RemoveSubscriber(Key, EntityEventBroker.PropertyChangedEventKey, value); } } @@ -251,8 +251,8 @@ public void Remove() } /// - /// Register the entity in removing queue. Removal operation will be postponed - /// until method is called; some query is executed + /// Register the entity in removing queue. Removal operation will be postponed + /// until method is called; some query is executed /// or current transaction is being committed. /// public void RemoveLater() @@ -265,14 +265,14 @@ public void Lock(LockMode lockMode, LockBehavior lockBehavior) { var parameterContext = new ParameterContext(); parameterContext.SetValue(keyParameter, Key.Value); - object key = new Triplet(TypeInfo, lockMode, lockBehavior); + object key = (TypeInfo, lockMode, lockBehavior); Func generator = tripletObj => { - var triplet = (Triplet) tripletObj; - var index = triplet.First.Indexes.PrimaryIndex; + var triplet = ((TypeInfo, LockMode, LockBehavior)) tripletObj; + var index = triplet.Item1.Indexes.PrimaryIndex; var query = index.GetQuery() .Seek(context => context.GetValue(keyParameter)) - .Lock(() => triplet.Second, () => triplet.Third) - .Select(); + .Lock(() => triplet.Item2, () => triplet.Item3) + .Select(Array.Empty()); return Session.Compile(query); }; var source = (ExecutableProvider) Session.StorageNode.InternalQueryCache.GetOrAdd(key, generator); @@ -355,7 +355,7 @@ protected internal bool UpdateVersionInfo(Entity changedEntity, FieldInfo change bool changed = false; try { State.IsVersionInfoUpdated = true; // Prevents recursion - if (!TypeInfo.HasVersionRoots) + if (!TypeInfo.HasVersionRoots) changed = SystemUpdateVersionInfo(changedEntity, changedField); else { foreach (var root in ((IHasVersionRoots) this).GetVersionRoots()) { @@ -540,14 +540,14 @@ internal override sealed void SystemBeforeInitialize(bool materialize) OrmLog.Debug(Strings.LogSessionXMaterializingYKeyZ, Session, GetType().GetShortName(), State.Key); } - if (Session.IsSystemLogicOnly || materialize) + if (Session.IsSystemLogicOnly || materialize) return; // Not necessity to use // Session.Operations.EnableSystemOperationRegistration() // here, because there is no higher level system operation // for this one, or system op. registration is already enabled. - + bool hasKeyGenerator = Session.Domain.KeyGenerators[TypeInfo.Key]!=null; if (hasKeyGenerator) { Session.SystemEvents.NotifyKeyGenerated(Key); @@ -739,7 +739,7 @@ internal override sealed void SystemBeforeTupleChange() internal override void SystemTupleChange() { if (PersistenceState!=PersistenceState.New && PersistenceState!=PersistenceState.Modified) { - Session.EnforceChangeRegistrySizeLimit(); // Must be done before the next line + Session.EnforceChangeRegistrySizeLimit(); // Must be done before the next line // to avoid post-first property set flush. State.PersistenceState = PersistenceState.Modified; } @@ -826,7 +826,7 @@ protected Entity() SystemBeforeInitialize(false); } catch (Exception error) { - InitializationError(GetType(), error); + InitializationError(GetType(), error); // GetType() call is correct here: no code will be executed further, // if base constructor will fail, but since descendant's constructor is aspected, // we must "simulate" its own call of InitializationError method. @@ -888,7 +888,7 @@ internal Entity(Session session, Tuple keyTuple) /// { /// [Field, KeyField] /// public string ISBN { get; set; } - /// + /// /// public Book(string isbn) : base(isbn) { } /// } /// @@ -919,7 +919,7 @@ protected Entity(params object[] values) SystemBeforeInitialize(false); } catch (Exception error) { - InitializationError(GetType(), error); + InitializationError(GetType(), error); // GetType() call is correct here: no code will be executed further, // if base constructor will fail, but since descendant's constructor is aspected, // we must "simulate" its own call of InitializationError method. @@ -934,7 +934,7 @@ protected Entity(params object[] values) /// The field values that will be used for key building. /// Use this kind of constructor when you need to explicitly set key for this instance. /// - /// + /// /// [HierarchyRoot] /// public class Book : Entity /// { @@ -962,7 +962,7 @@ protected Entity(Session session, params object[] values) using (Session.DisableSaveChanges(this)) { foreach (var referenceField in references) { var referenceValue = (Entity) GetFieldValue(referenceField); - Session.PairSyncManager.ProcessRecursively(null, null, + Session.PairSyncManager.ProcessRecursively(null, null, PairIntegrity.OperationType.Set, referenceField.GetAssociation(referenceValue.TypeInfo), this, referenceValue, null); } } @@ -971,7 +971,7 @@ protected Entity(Session session, params object[] values) SystemBeforeInitialize(false); } catch (Exception error) { - InitializationError(GetType(), error); + InitializationError(GetType(), error); // GetType() call is correct here: no code will be executed further, // if base constructor will fail, but since descendant's constructor is aspected, // we must "simulate" its own call of InitializationError method. diff --git a/Orm/Xtensive.Orm/Orm/Internals/Prefetch/EntityGroupTask.cs b/Orm/Xtensive.Orm/Orm/Internals/Prefetch/EntityGroupTask.cs index 104d6092bb..16c62c6287 100644 --- a/Orm/Xtensive.Orm/Orm/Internals/Prefetch/EntityGroupTask.cs +++ b/Orm/Xtensive.Orm/Orm/Internals/Prefetch/EntityGroupTask.cs @@ -45,18 +45,8 @@ public bool Equals(CacheKey other) return true; } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) { - return false; - } - - if (obj.GetType() != typeof(CacheKey)) { - return false; - } - - return Equals((CacheKey) obj); - } + public override bool Equals(object obj) => + obj is CacheKey other && Equals(other); public override int GetHashCode() => cachedHashCode; @@ -132,18 +122,9 @@ public bool Equals(EntityGroupTask other) return ReferenceEquals(this, other) || other.cacheKey.Equals(cacheKey); } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) { - return false; - } - - if (ReferenceEquals(this, obj)) { - return true; - } - - return obj is EntityGroupTask entityGroupTask && Equals(entityGroupTask); - } + public override bool Equals(object obj) => + ReferenceEquals(this, obj) + || obj is EntityGroupTask other && Equals(other); public override int GetHashCode() => cacheKey.GetHashCode(); diff --git a/Orm/Xtensive.Orm/Orm/Internals/Prefetch/EntitySetTask.cs b/Orm/Xtensive.Orm/Orm/Internals/Prefetch/EntitySetTask.cs index df86de07a8..6c27b4531c 100644 --- a/Orm/Xtensive.Orm/Orm/Internals/Prefetch/EntitySetTask.cs +++ b/Orm/Xtensive.Orm/Orm/Internals/Prefetch/EntitySetTask.cs @@ -36,16 +36,8 @@ public bool Equals(CacheKey other) && Equals(other.ReferencingField, ReferencingField); } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) { - return false; - } - if (obj.GetType() != typeof (CacheKey)) { - return false; - } - return Equals((CacheKey) obj); - } + public override bool Equals(object obj) => + obj is CacheKey other && Equals(other); public override int GetHashCode() => cachedHashCode; @@ -158,19 +150,9 @@ public bool Equals(EntitySetTask other) return other.cacheKey.Equals(cacheKey); } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) { - return false; - } - if (ReferenceEquals(this, obj)) { - return true; - } - if (obj.GetType() != typeof (EntitySetTask)) { - return false; - } - return Equals((EntitySetTask) obj); - } + public override bool Equals(object obj) => + ReferenceEquals(this, obj) + || obj is EntitySetTask other && Equals(other); public override int GetHashCode() => cacheKey.GetHashCode(); @@ -205,7 +187,7 @@ private static CompilableProvider CreateRecordSetLoadingItems(object cachingKey) var result = association.AuxiliaryType == null ? CreateQueryForDirectAssociation(pair, primaryTargetIndex, resultColumns) : CreateQueryForAssociationViaAuxType(pair, primaryTargetIndex, resultColumns); - result = result.Select(resultColumns.ToArray()); + result = result.Select(resultColumns); if (pair.Second.ItemCountLimit != null) result = result.Take(context => context.GetValue(itemCountLimitParameter)); return result; diff --git a/Orm/Xtensive.Orm/Orm/Internals/Prefetch/GraphContainer.cs b/Orm/Xtensive.Orm/Orm/Internals/Prefetch/GraphContainer.cs index e2400a5639..24f742bb60 100644 --- a/Orm/Xtensive.Orm/Orm/Internals/Prefetch/GraphContainer.cs +++ b/Orm/Xtensive.Orm/Orm/Internals/Prefetch/GraphContainer.cs @@ -110,17 +110,9 @@ public bool Equals(GraphContainer other) return Key.Equals(other.Key); } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - return false; - if (ReferenceEquals(this, obj)) - return true; - var otherType = obj.GetType(); - if (otherType != (typeof(GraphContainer))) - return false; - return Equals((GraphContainer) obj); - } + public override bool Equals(object obj) => + ReferenceEquals(this, obj) + || obj is GraphContainer other && Equals(other); public override int GetHashCode() { diff --git a/Orm/Xtensive.Orm/Orm/Internals/Prefetch/PrefetchFieldDescriptor.cs b/Orm/Xtensive.Orm/Orm/Internals/Prefetch/PrefetchFieldDescriptor.cs index 13f3d0a4be..9d9b413977 100644 --- a/Orm/Xtensive.Orm/Orm/Internals/Prefetch/PrefetchFieldDescriptor.cs +++ b/Orm/Xtensive.Orm/Orm/Internals/Prefetch/PrefetchFieldDescriptor.cs @@ -15,7 +15,7 @@ namespace Xtensive.Orm.Internals.Prefetch /// Descriptor of a field's fetching request. /// [Serializable] - public class PrefetchFieldDescriptor + public sealed class PrefetchFieldDescriptor { private readonly Action keyExtractionSubscriber; @@ -52,15 +52,8 @@ public bool Equals(PrefetchFieldDescriptor other) } /// - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) { - return false; - } - return obj.GetType() != typeof(PrefetchFieldDescriptor) - ? false : - Equals((PrefetchFieldDescriptor) obj); - } + public override bool Equals(object obj) => + obj is PrefetchFieldDescriptor other && Equals(other); /// public override int GetHashCode() diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs index bfe6204813..6f997f3559 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs @@ -24,7 +24,7 @@ public Expression Remap(int offset, Dictionary processed return new ColumnExpression(Type, newMapping, OuterParameter, DefaultIfEmpty); } - public Expression Remap(int[] map, Dictionary processedExpressions) + public Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { if (!CanRemap) return this; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ConstructorExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ConstructorExpression.cs index 8812b53eee..2451ab02f8 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ConstructorExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ConstructorExpression.cs @@ -74,7 +74,7 @@ public Expression Remap(int offset, Dictionary processed return result; } - public Expression Remap(int[] map, Dictionary processedExpressions) + public Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { Func remapper = delegate(IMappedExpression mapped) { var parametrizedExpression = mapped as ParameterizedExpression; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs index ca87f4fb99..575b18d804 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs @@ -58,7 +58,7 @@ public Expression Remap(int offset, Dictionary processed return result; } - public Expression Remap(int[] map, Dictionary processedExpressions) + public Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { if (!CanRemap) { return this; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs index c356d3ce5c..a6240b64ed 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs @@ -59,7 +59,7 @@ public override Expression Remap(int offset, Dictionary return result; } - public override Expression Remap(int[] map, Dictionary processedExpressions) + public override Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { if (!CanRemap) { return this; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntitySetExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntitySetExpression.cs index eeb6b67e8d..458ca11bd6 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntitySetExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntitySetExpression.cs @@ -60,7 +60,7 @@ public override Expression Remap(int offset, Dictionary return result; } - public override Expression Remap(int[] map, Dictionary processedExpressions) + public override Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { if (!CanRemap) return this; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/FieldExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/FieldExpression.cs index 089406138e..b5aee9f1d4 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/FieldExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/FieldExpression.cs @@ -51,7 +51,7 @@ public override Expression Remap(int offset, Dictionary return result; } - public override Expression Remap(int[] map, Dictionary processedExpressions) + public override Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { if (!CanRemap) { return this; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs index 0070184420..35f2e3b0e1 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs @@ -59,7 +59,7 @@ public Expression Remap(int offset, Dictionary processed return new FullTextExpression(FullTextIndex, remappedEntityExpression, remappedRankExpression, OuterParameter); } - public Expression Remap(int[] map, Dictionary processedExpressions) + public Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { if (!CanRemap) return this; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/GroupingExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/GroupingExpression.cs index 4ee143f7f8..4335650600 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/GroupingExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/GroupingExpression.cs @@ -70,7 +70,7 @@ public override Expression RemoveOuterParameter(Dictionary processedExpressions) + public override Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { var remappedSubquery = (SubQueryExpression) base.Remap(map, processedExpressions); var remappedKeyExpression = GenericExpressionVisitor.Process(KeyExpression, mapped => mapped.Remap(map, processedExpressions)); diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/Interfaces/IMappedExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/Interfaces/IMappedExpression.cs index 55f40a1a9f..2bd7e557ff 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/Interfaces/IMappedExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/Interfaces/IMappedExpression.cs @@ -15,6 +15,6 @@ internal interface IMappedExpression Expression BindParameter(ParameterExpression parameter, Dictionary processedExpressions); Expression RemoveOuterParameter(Dictionary processedExpressions); Expression Remap(int offset, Dictionary processedExpressions); - Expression Remap(int[] map, Dictionary processedExpressions); + Expression Remap(IReadOnlyList map, Dictionary processedExpressions); } } \ No newline at end of file diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ItemProjectorExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ItemProjectorExpression.cs index c5123fef5f..bdd721afb6 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ItemProjectorExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ItemProjectorExpression.cs @@ -44,7 +44,7 @@ private static bool CheckItemIsPrimitive(Expression item) } } - public List GetColumns(ColumnExtractionModes columnExtractionModes) => + public IEnumerable GetColumns(ColumnExtractionModes columnExtractionModes) => ColumnGatherer.GetColumns(Item, columnExtractionModes); public List> GetColumnsAndExpressions(ColumnExtractionModes columnExtractionModes) => @@ -61,7 +61,7 @@ public ItemProjectorExpression Remap(CompilableProvider dataSource, int offset) return new ItemProjectorExpression(item, dataSource, Context, AggregateType); } - public ItemProjectorExpression Remap(CompilableProvider dataSource, int[] columnMap) + public ItemProjectorExpression Remap(CompilableProvider dataSource, IReadOnlyList columnMap) { var item = GenericExpressionVisitor .Process(Item, mapped => mapped.Remap(columnMap, new Dictionary())); diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/KeyExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/KeyExpression.cs index dcc934b485..0d8b6ff217 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/KeyExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/KeyExpression.cs @@ -46,7 +46,7 @@ private Expression RemapWithNoCheck(int offset, Dictionary processedExpressions) + public override Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { if (!CanRemap) { return this; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/LocalCollectionExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/LocalCollectionExpression.cs index 506ef782b2..ffcd4e9676 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/LocalCollectionExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/LocalCollectionExpression.cs @@ -49,7 +49,7 @@ public Expression Remap(int offset, Dictionary processed return result; } - public Expression Remap(int[] map, Dictionary processedExpressions) + public Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { if (!CanRemap) return this; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/PersistentFieldExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/PersistentFieldExpression.cs index de6989e5a8..c718771c1e 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/PersistentFieldExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/PersistentFieldExpression.cs @@ -22,7 +22,7 @@ internal abstract class PersistentFieldExpression : ParameterizedExpression, public abstract Expression BindParameter(ParameterExpression parameter, Dictionary processedExpressions); public abstract Expression RemoveOuterParameter(Dictionary processedExpressions); public abstract Expression Remap(int offset, Dictionary processedExpressions); - public abstract Expression Remap(int[] map, Dictionary processedExpressions); + public abstract Expression Remap(IReadOnlyList map, Dictionary processedExpressions); public override string ToString() { diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureExpression.cs index f8b2e99aa6..bb31cd358d 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureExpression.cs @@ -60,7 +60,7 @@ public Expression Remap(int offset, Dictionary processed } - public Expression Remap(int[] map, Dictionary processedExpressions) + public Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { if (!CanRemap) { return this; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureFieldExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureFieldExpression.cs index 610021b572..f08de19cdf 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureFieldExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureFieldExpression.cs @@ -61,7 +61,7 @@ public override Expression Remap(int offset, Dictionary return result; } - public override Expression Remap(int[] map, Dictionary processedExpressions) + public override Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { if (!CanRemap) { return this; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/SubQueryExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/SubQueryExpression.cs index 6053e839bd..288cae96ff 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/SubQueryExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/SubQueryExpression.cs @@ -67,7 +67,7 @@ public virtual Expression Remap(int offset, Dictionary p return result; } - public virtual Expression Remap(int[] map, Dictionary processedExpressions) + public virtual Expression Remap(IReadOnlyList map, Dictionary processedExpressions) { // Don't check CanRemap - Remap always. diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/Visitors/ColumnGatherer.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/Visitors/ColumnGatherer.cs index 7aeb0ded4e..4516c5a72b 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/Visitors/ColumnGatherer.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/Visitors/ColumnGatherer.cs @@ -57,7 +57,7 @@ public static List> GetColumnsAndExpressions(Expression ex return ordered.ToList(); } - public static List GetColumns(Expression expression, ColumnExtractionModes columnExtractionModes) + public static IEnumerable GetColumns(Expression expression, ColumnExtractionModes columnExtractionModes) { var gatherer = new ColumnGatherer(columnExtractionModes); gatherer.Visit(expression); @@ -67,7 +67,7 @@ public static List GetColumns(Expression expression, ColumnExtractionModes var ordered = gatherer.OrderedValues ? distinct.OrderBy(i => i) : distinct; - return ordered.ToList(); + return ordered; } protected override Expression VisitMarker(MarkerExpression expression) diff --git a/Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs b/Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs index 890c7ee566..ea92244168 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs @@ -1228,7 +1228,7 @@ private static IList GetAnonymousArguments(Expression expression, Ty var newExpression = ((NewExpression) expression); IEnumerable arguments = newExpression .Members - .Select((methodInfo, index) => new {methodInfo.Name, Argument = newExpression.Arguments[index]}) + .Select((methodInfo, index) => (methodInfo.Name, Argument: newExpression.Arguments[index])) .OrderBy(a => a.Name) .Select(a => a.Argument); return arguments.ToList(); diff --git a/Orm/Xtensive.Orm/Orm/Linq/Translator.Materialization.cs b/Orm/Xtensive.Orm/Orm/Linq/Translator.Materialization.cs index 60b70d7387..0f8318085f 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Translator.Materialization.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Translator.Materialization.cs @@ -87,7 +87,7 @@ private static ProjectionExpression Optimize(ProjectionExpression origin) usedColumns.Add(0); if (usedColumns.Count < origin.ItemProjector.DataSource.Header.Length) { var resultProvider = new SelectProvider(originProvider, usedColumns.ToArray()); - var itemProjector = origin.ItemProjector.Remap(resultProvider, usedColumns.ToArray()); + var itemProjector = origin.ItemProjector.Remap(resultProvider, usedColumns); var result = new ProjectionExpression( origin.Type, itemProjector, diff --git a/Orm/Xtensive.Orm/Orm/Linq/Translator.Queryable.cs b/Orm/Xtensive.Orm/Orm/Linq/Translator.Queryable.cs index 4079aec5b6..059360c511 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Translator.Queryable.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Translator.Queryable.cs @@ -326,7 +326,7 @@ private ProjectionExpression VisitOfType(Expression source, Type targetType, Typ currentIndex++; } - var recordSet = targetTypeInfo.Indexes.PrimaryIndex.GetQuery().Alias(context.GetNextAlias()).Select(indexes.ToArray()); + var recordSet = targetTypeInfo.Indexes.PrimaryIndex.GetQuery().Alias(context.GetNextAlias()).Select(indexes); var keySegment = visitedSource.ItemProjector.GetColumns(ColumnExtractionModes.TreatEntityAsKey); var keyPairs = keySegment .Select((leftIndex, rightIndex) => new Pair(leftIndex, rightIndex)) @@ -870,7 +870,7 @@ private Pair VisitAggregateSource(Expression source, sourceProjection = VisitSequence(source); if (aggregateParameter == null) { if (sourceProjection.ItemProjector.IsPrimitive) { - columnList = sourceProjection.ItemProjector.GetColumns(ColumnExtractionModes.TreatEntityAsKey); + columnList = sourceProjection.ItemProjector.GetColumns(ColumnExtractionModes.TreatEntityAsKey).ToList(); } else { var lambdaType = sourceProjection.ItemProjector.Item.Type; @@ -889,7 +889,7 @@ private Pair VisitAggregateSource(Expression source, string.Format(Strings.ExAggregatesForNonPrimitiveTypesAreNotSupported, visitedExpression)); } - columnList = result.GetColumns(ColumnExtractionModes.TreatEntityAsKey); + columnList = result.GetColumns(ColumnExtractionModes.TreatEntityAsKey).ToList(); sourceProjection = context.Bindings[aggregateParameter.Parameters[0]]; } } @@ -990,11 +990,11 @@ private ProjectionExpression VisitGroupBy(Type returnType, Expression source, La // subqueryIndex - values of array // groupIndex - indexes of values of array var comparisonInfos = keyColumns - .Select((subqueryIndex, groupIndex) => new { - SubQueryIndex = subqueryIndex, - GroupIndex = groupIndex, - Type = keyDataSource.Header.Columns[groupIndex].Type.ToNullable() - }) + .Select((subqueryIndex, groupIndex) => ( + SubQueryIndex: subqueryIndex, + GroupIndex: groupIndex, + Type: keyDataSource.Header.Columns[groupIndex].Type.ToNullable() + )) .ToList(); var applyParameter = context.GetApplyParameter(groupingProjection); @@ -1589,19 +1589,18 @@ private Expression VisitSetOperations(Expression outerSource, Expression innerSo var outerItemProjector = outer.ItemProjector.RemoveOwner(); var innerItemProjector = inner.ItemProjector.RemoveOwner(); - var outerColumnList = outerItemProjector.GetColumns(ColumnExtractionModes.Distinct); - var innerColumnList = innerItemProjector.GetColumns(ColumnExtractionModes.Distinct); + var outerColumnList = outerItemProjector.GetColumns(ColumnExtractionModes.Distinct).ToList(); + var innerColumnList = innerItemProjector.GetColumns(ColumnExtractionModes.Distinct).ToList(); if (!outerColumnList.Except(innerColumnList).Any() && outerColumnList.Count == innerColumnList.Count) { outerColumnList = outerColumnList.OrderBy(i => i).ToList(); innerColumnList = innerColumnList.OrderBy(i => i).ToList(); } - var outerColumns = outerColumnList.ToArray(); var outerRecordSet = ShouldWrapDataSourceWithSelect(outerItemProjector, outerColumnList) - ? outerItemProjector.DataSource.Select(outerColumns) + ? outerItemProjector.DataSource.Select(outerColumnList) : outerItemProjector.DataSource; var innerRecordSet = ShouldWrapDataSourceWithSelect(innerItemProjector, innerColumnList) - ? innerItemProjector.DataSource.Select(innerColumnList.ToArray()) + ? innerItemProjector.DataSource.Select(innerColumnList) : innerItemProjector.DataSource; var recordSet = outerItemProjector.DataSource; @@ -1622,14 +1621,14 @@ private Expression VisitSetOperations(Expression outerSource, Expression innerSo var tupleParameterBindings = outer.TupleParameterBindings.Union(inner.TupleParameterBindings) .ToDictionary(pair => pair.Key, pair => pair.Value); - var itemProjector = outerItemProjector.Remap(recordSet, outerColumns); + var itemProjector = outerItemProjector.Remap(recordSet, outerColumnList); return new ProjectionExpression(outer.Type, itemProjector, tupleParameterBindings); } - private bool ShouldWrapDataSourceWithSelect(ItemProjectorExpression expression, ICollection columns) => + private bool ShouldWrapDataSourceWithSelect(ItemProjectorExpression expression, IReadOnlyList columns) => expression.DataSource.Type != ProviderType.Select || expression.DataSource.Header.Length != columns.Count - || columns.Select((c, i) => new { c, i }).Any(x => x.c != x.i); + || columns.Select((c, i) => (c, i)).Any(x => x.c != x.i); private Expression AddSubqueryColumn(Type columnType, CompilableProvider subquery) { diff --git a/Orm/Xtensive.Orm/Orm/Linq/WellKnownMembers.cs b/Orm/Xtensive.Orm/Orm/Linq/WellKnownMembers.cs index ca60b89507..422be519c7 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/WellKnownMembers.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/WellKnownMembers.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2009-2020 Xtensive LLC. +// Copyright (C) 2009-2020 Xtensive LLC. // This code is distributed under MIT license terms. // See the License.txt file in the project root for more information. // Created by: Denis Krjuchkov @@ -55,7 +55,7 @@ static Query() .Single(ft => ft.GetParameters().Length==2 && ft.GetParameterTypes()[0]==typeof(Expression>) && ft.GetParameterTypes()[1]==WellKnownTypes.Int32); var containsTableMethods = typeof (Orm.Query).GetMethods() .Where(m => m.Name==nameof(Orm.Query.ContainsTable)) - .Select(m => new {Method = m, ParameterTypes = m.GetParameterTypes()}).ToArray(); + .Select(m => (Method: m, ParameterTypes: m.GetParameterTypes())).ToArray(); ContainsTableExpr = containsTableMethods .Single(g => g.ParameterTypes.Length==1 && g.ParameterTypes[0]==typeof (Expression>)).Method; ContainsTableExprWithColumns = containsTableMethods @@ -113,7 +113,7 @@ static QueryEndpoint() .Single(ft => ft.GetParameters().Length==2 && ft.GetParameterTypes()[0]==typeof(Expression>) && ft.GetParameterTypes()[1]==WellKnownTypes.Int32); var containsTableMethods = typeof (Orm.QueryEndpoint).GetMethods() .Where(m => m.Name==nameof(Orm.QueryEndpoint.ContainsTable)) - .Select(m=> new {Method = m, ParameterTypes = m.GetParameterTypes()}).ToArray(); + .Select(m=> (Method: m, ParameterTypes: m.GetParameterTypes())).ToArray(); ContainsTableExpr = containsTableMethods .Single(g => g.ParameterTypes.Length==1 && g.ParameterTypes[0]==typeof (Expression>)).Method; ContainsTableExprWithColumns = containsTableMethods diff --git a/Orm/Xtensive.Orm/Orm/Model/ColumnInfo.cs b/Orm/Xtensive.Orm/Orm/Model/ColumnInfo.cs index dbd9a6f7a9..efeac31133 100644 --- a/Orm/Xtensive.Orm/Orm/Model/ColumnInfo.cs +++ b/Orm/Xtensive.Orm/Orm/Model/ColumnInfo.cs @@ -231,14 +231,9 @@ public bool Equals(ColumnInfo obj) } /// - public override bool Equals(object obj) - { - if (ReferenceEquals(this, obj)) - return true; - if (obj.GetType()!=typeof (ColumnInfo)) - return false; - return Equals((ColumnInfo) obj); - } + public override bool Equals(object obj) => + ReferenceEquals(this, obj) + || obj is ColumnInfo other && Equals(other); /// public override int GetHashCode() diff --git a/Orm/Xtensive.Orm/Orm/Model/FieldInfo.cs b/Orm/Xtensive.Orm/Orm/Model/FieldInfo.cs index f2dadf0cba..ffd88e0783 100644 --- a/Orm/Xtensive.Orm/Orm/Model/FieldInfo.cs +++ b/Orm/Xtensive.Orm/Orm/Model/FieldInfo.cs @@ -726,14 +726,9 @@ public bool Equals(FieldInfo obj) } /// - public override bool Equals(object obj) - { - if (ReferenceEquals(this, obj)) - return true; - if (obj.GetType() != typeof(FieldInfo)) - return false; - return Equals((FieldInfo) obj); - } + public override bool Equals(object obj) => + ReferenceEquals(this, obj) + || obj is FieldInfo other && Equals(other); /// public override int GetHashCode() diff --git a/Orm/Xtensive.Orm/Orm/Model/KeyField.cs b/Orm/Xtensive.Orm/Orm/Model/KeyField.cs index b77adfc0b9..1856846ce9 100644 --- a/Orm/Xtensive.Orm/Orm/Model/KeyField.cs +++ b/Orm/Xtensive.Orm/Orm/Model/KeyField.cs @@ -28,15 +28,9 @@ public override int GetHashCode() } /// - public override bool Equals(object obj) - { - var kf = obj as KeyField; - if (kf == null) - return false; - if (ReferenceEquals(this, kf)) - return true; - return (Name==kf.Name && Direction==kf.Direction); - } + public override bool Equals(object obj) => + ReferenceEquals(this, obj) + || obj is KeyField kf && Name == kf.Name && Direction == kf.Direction; // Constructors diff --git a/Orm/Xtensive.Orm/Orm/Model/ModelVisitor.cs b/Orm/Xtensive.Orm/Orm/Model/ModelVisitor.cs index 47c65c5933..71ecc7dedd 100644 --- a/Orm/Xtensive.Orm/Orm/Model/ModelVisitor.cs +++ b/Orm/Xtensive.Orm/Orm/Model/ModelVisitor.cs @@ -22,44 +22,21 @@ public abstract class ModelVisitor /// The node. /// Visit result. /// Node type is unknown. - protected virtual TResult Visit(Node node) - { - var domainModel = node as DomainModel; - if (domainModel != null) - return VisitDomainModel(domainModel); - var keyProviderInfo = node as KeyInfo; - if (keyProviderInfo != null) - return VisitKeyInfo(keyProviderInfo); - var sequenceInfo = node as SequenceInfo; - if (sequenceInfo != null) - return VisitSequenceInfo(sequenceInfo); - var keyField = node as KeyField; - if (keyField != null) - return VisitKeyField(keyField); - var association = node as AssociationInfo; - if (association != null) - return VisitAssociationInfo(association); - var field = node as FieldInfo; - if (field != null) - return VisitFieldInfo(field); - var type = node as TypeInfo; - if (type != null) - return VisitTypeInfo(type); - var column = node as ColumnInfo; - if (column != null) - return VisitColumnInfo(column); - var hierarchy = node as HierarchyInfo; - if (hierarchy != null) - return VisitHierarchyInfo(hierarchy); - var index = node as IndexInfo; - if (index != null) - return VisitIndexInfo(index); - var fullTextIndex = node as FullTextIndexInfo; - if (fullTextIndex != null) - return VisitFullTextIndexInfo(fullTextIndex); - - throw new ArgumentException(Strings.ExNodeTypeIsUnknown, "node"); - } + protected virtual TResult Visit(Node node) => + node switch { + DomainModel domainModel => VisitDomainModel(domainModel), + KeyInfo keyProviderInfo => VisitKeyInfo(keyProviderInfo), + SequenceInfo sequenceInfo => VisitSequenceInfo(sequenceInfo), + KeyField keyField => VisitKeyField(keyField), + AssociationInfo association => VisitAssociationInfo(association), + FieldInfo field => VisitFieldInfo(field), + TypeInfo type => VisitTypeInfo(type), + ColumnInfo column => VisitColumnInfo(column), + HierarchyInfo hierarchy => VisitHierarchyInfo(hierarchy), + IndexInfo index => VisitIndexInfo(index), + FullTextIndexInfo fullTextIndex => VisitFullTextIndexInfo(fullTextIndex), + _ => throw new ArgumentException(Strings.ExNodeTypeIsUnknown, "node") + }; /// /// Visits key field. diff --git a/Orm/Xtensive.Orm/Orm/Model/TypeIndexInfoCollection.cs b/Orm/Xtensive.Orm/Orm/Model/TypeIndexInfoCollection.cs index 328b686f4c..fd8e68a3d9 100644 --- a/Orm/Xtensive.Orm/Orm/Model/TypeIndexInfoCollection.cs +++ b/Orm/Xtensive.Orm/Orm/Model/TypeIndexInfoCollection.cs @@ -110,7 +110,7 @@ private IndexInfo GetIndex(IEnumerable fields) var candidates = this .Where(i => i.KeyColumns .TakeWhile((_, index) => index < columns.Count) - .Select((pair, index) => new {column = pair.Key, columnIndex = index}) + .Select((pair, index) => (column: pair.Key, columnIndex: index)) .All(p => p.column==columns[p.columnIndex])) .OrderByDescending(i => i.Attributes).ToList(); diff --git a/Orm/Xtensive.Orm/Orm/Providers/Expressions/QueryParameterIdentity.cs b/Orm/Xtensive.Orm/Orm/Providers/Expressions/QueryParameterIdentity.cs index 97371ae206..d7ae45b660 100644 --- a/Orm/Xtensive.Orm/Orm/Providers/Expressions/QueryParameterIdentity.cs +++ b/Orm/Xtensive.Orm/Orm/Providers/Expressions/QueryParameterIdentity.cs @@ -53,14 +53,9 @@ public override int GetHashCode() return !Equals(left, right); } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - return false; - if (ReferenceEquals(this, obj)) - return true; - return obj is QueryParameterIdentity && Equals((QueryParameterIdentity) obj); - } + public override bool Equals(object obj) => + ReferenceEquals(this, obj) + || obj is QueryParameterIdentity other && Equals(other); // Constructors diff --git a/Orm/Xtensive.Orm/Orm/Providers/Requests/PersistRequestBuilderTask.cs b/Orm/Xtensive.Orm/Orm/Providers/Requests/PersistRequestBuilderTask.cs index e4ba368056..0acabb0291 100644 --- a/Orm/Xtensive.Orm/Orm/Providers/Requests/PersistRequestBuilderTask.cs +++ b/Orm/Xtensive.Orm/Orm/Providers/Requests/PersistRequestBuilderTask.cs @@ -45,21 +45,19 @@ public sealed class PersistRequestBuilderTask /// public override bool Equals(object obj) { - if (obj==null) - return false; if (ReferenceEquals(this, obj)) return true; - var other = obj as PersistRequestBuilderTask; - if (other==null) - return false; - if (Type!=other.Type) - return false; - if (Kind!=other.Kind) - return false; - if (ValidateVersion!=other.ValidateVersion) - return false; - return CompareBits(AvailableFields, other.AvailableFields) - && CompareBits(ChangedFields, other.ChangedFields); + if (obj is PersistRequestBuilderTask other) { + if (Type != other.Type) + return false; + if (Kind != other.Kind) + return false; + if (ValidateVersion != other.ValidateVersion) + return false; + return CompareBits(AvailableFields, other.AvailableFields) + && CompareBits(ChangedFields, other.ChangedFields); + } + return false; } /// diff --git a/Orm/Xtensive.Orm/Orm/Providers/SessionHandler.References.cs b/Orm/Xtensive.Orm/Orm/Providers/SessionHandler.References.cs index 776735b7f3..0764c26b1d 100644 --- a/Orm/Xtensive.Orm/Orm/Providers/SessionHandler.References.cs +++ b/Orm/Xtensive.Orm/Orm/Providers/SessionHandler.References.cs @@ -104,7 +104,7 @@ private static Pair> BuildReferencingQuery( var index = association.OwnerType.Indexes.PrimaryIndex; var nonLazyColumnsSelector = index .Columns - .Select((column, i)=>new {Column = column, Index = i}) + .Select((column, i) => (Column: column, Index: i)) .Where(a=>!a.Column.IsLazyLoad) .Select(a=>a.Index) .ToArray(); @@ -122,7 +122,7 @@ private static Pair> BuildReferencingQuery( var targetIndex = association.TargetType.Indexes.PrimaryIndex; var nonLazyColumnsSelector = index .Columns - .Select((column, i)=>new {Column = column, Index = i}) + .Select((column, i) => (Column: column, Index: i)) .Where(a=>!a.Column.IsLazyLoad) .Select(a=>targetIndex.Columns.Count + a.Index) .ToArray(); @@ -152,7 +152,7 @@ private static Pair> BuildReferencingQuery( var targetIndex = association.AuxiliaryType.Indexes.PrimaryIndex; var nonLazyColumnsSelector = index .Columns - .Select((column, i)=>new {Column = column, Index = i}) + .Select((column, i) => (Column: column, Index: i)) .Where(a=>!a.Column.IsLazyLoad) .Select(a=>targetIndex.Columns.Count + a.Index) .ToArray(); diff --git a/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.Index.cs b/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.Index.cs index cecba5fabb..e66873e751 100644 --- a/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.Index.cs +++ b/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.Index.cs @@ -168,7 +168,7 @@ private SqlSelect BuildFilteredQuery(IndexInfo index) var columnType = discriminatorMap.Column.ValueType; var discriminatorColumnIndex = underlyingIndex.Columns .Where(c => !c.Field.IsTypeId) - .Select((c,i) => new {c,i}) + .Select((c, i) => (c, i)) .Where(p => p.c == discriminatorMap.Column) .Single().i; var discriminatorColumn = baseQuery.From.Columns[discriminatorColumnIndex]; @@ -220,7 +220,7 @@ private SqlSelect BuildTypedQuery(IndexInfo index) var baseColumns = baseQuery.Columns.ToList(); var typeIdColumnIndex = index.Columns - .Select((c, i) => new {c.Field, i}) + .Select((c, i) => (c.Field, i)) .Single(p => p.Field.IsTypeId && p.Field.IsSystem).i; var type = index.ReflectedType; var typeIdColumn = SqlDml.ColumnRef( diff --git a/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.cs b/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.cs index acc08ada5a..1794cc7710 100644 --- a/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.cs +++ b/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.cs @@ -74,20 +74,23 @@ protected override SqlProvider VisitAlias(AliasProvider provider) SqlSelect sourceSelect = source.Request.Statement; var sqlSelect = sourceSelect.ShallowClone(); - var columns = sqlSelect.Columns.ToList(); - sqlSelect.Columns.Clear(); + var sqlSelectColumns = sqlSelect.Columns; + var columns = sqlSelectColumns.ToList(); + sqlSelectColumns.Clear(); for (int i = 0; i < columns.Count; i++) { var columnName = provider.Header.Columns[i].Name; columnName = ProcessAliasedName(columnName); - var column = columns[i]; - var columnRef = column as SqlColumnRef; - var columnStub = column as SqlColumnStub; - if (!ReferenceEquals(null, columnRef)) - sqlSelect.Columns.Add(SqlDml.ColumnRef(columnRef.SqlColumn, columnName)); - else if (!ReferenceEquals(null, columnStub)) - sqlSelect.Columns.Add(columnStub); - else - sqlSelect.Columns.Add(column, columnName); + switch (columns[i]) { + case SqlColumnRef columnRef: + sqlSelectColumns.Add(SqlDml.ColumnRef(columnRef.SqlColumn, columnName)); + break; + case SqlColumnStub columnStub: + sqlSelectColumns.Add(columnStub); + break; + case var column: + sqlSelectColumns.Add(column, columnName); + break; + } } return CreateProvider(sqlSelect, provider, source); } diff --git a/Orm/Xtensive.Orm/Orm/Providers/SqlIncludeProvider.cs b/Orm/Xtensive.Orm/Orm/Providers/SqlIncludeProvider.cs index 4fe179d51a..c42a30cc15 100644 --- a/Orm/Xtensive.Orm/Orm/Providers/SqlIncludeProvider.cs +++ b/Orm/Xtensive.Orm/Orm/Providers/SqlIncludeProvider.cs @@ -27,8 +27,8 @@ public bool Equals(RowFilterParameter other) => && (ReferenceEquals(this, other) || ReferenceEquals(temporaryTableDescriptor, other.temporaryTableDescriptor)); public override bool Equals(object obj) => - !ReferenceEquals(null, obj) - && (ReferenceEquals(this, obj) || (obj is RowFilterParameter rowFilterParameter && Equals(rowFilterParameter))); + ReferenceEquals(this, obj) + || obj is RowFilterParameter other && Equals(other); public override int GetHashCode() => temporaryTableDescriptor != null ? temporaryTableDescriptor.GetHashCode() : 0; diff --git a/Orm/Xtensive.Orm/Orm/Rse/CompilableProviderExtensions.cs b/Orm/Xtensive.Orm/Orm/Rse/CompilableProviderExtensions.cs index 4753b2fa2b..3d98832818 100644 --- a/Orm/Xtensive.Orm/Orm/Rse/CompilableProviderExtensions.cs +++ b/Orm/Xtensive.Orm/Orm/Rse/CompilableProviderExtensions.cs @@ -80,7 +80,7 @@ public static CompilableProvider Filter(this CompilableProvider source, Expressi return new FilterProvider(source, predicate); } - public static CompilableProvider Select(this CompilableProvider source, params int[] columnIndexes) + public static CompilableProvider Select(this CompilableProvider source, IReadOnlyList columnIndexes) { ArgumentValidator.EnsureArgumentNotNull(columnIndexes, "columnIndexes"); return new SelectProvider(source, columnIndexes); diff --git a/Orm/Xtensive.Orm/Orm/Rse/Transformation/ColumnMappingInspector.cs b/Orm/Xtensive.Orm/Orm/Rse/Transformation/ColumnMappingInspector.cs index 36bf64c3c9..257716a6a2 100644 --- a/Orm/Xtensive.Orm/Orm/Rse/Transformation/ColumnMappingInspector.cs +++ b/Orm/Xtensive.Orm/Orm/Rse/Transformation/ColumnMappingInspector.cs @@ -395,7 +395,7 @@ private static CompilableProvider BuildSetOperationSource(CompilableProvider pro } var columns = expectedColumns - .Select(originalIndex => new { OriginalIndex = originalIndex, NewIndex = returningColumns.IndexOf(originalIndex) }) + .Select(originalIndex => (OriginalIndex: originalIndex, NewIndex: returningColumns.IndexOf(originalIndex))) .Select(x => x.NewIndex < 0 ? x.OriginalIndex : x.NewIndex).ToArray(expectedColumns.Count); return new SelectProvider(provider, columns); } diff --git a/Orm/Xtensive.Orm/Orm/Structure.cs b/Orm/Xtensive.Orm/Orm/Structure.cs index a364127197..a77223a50d 100644 --- a/Orm/Xtensive.Orm/Orm/Structure.cs +++ b/Orm/Xtensive.Orm/Orm/Structure.cs @@ -312,13 +312,8 @@ protected override sealed Pair GetSubscription(object eventKey) } /// - public override bool Equals(object obj) - { - if (obj==null || !(obj is Structure)) { - return false; - } - return Equals((Structure) obj); - } + public override bool Equals(object obj) => + obj is Structure other && Equals(other); /// public bool Equals(Structure other) diff --git a/Orm/Xtensive.Orm/Orm/Upgrade/Hints/UpgradeHint.cs b/Orm/Xtensive.Orm/Orm/Upgrade/Hints/UpgradeHint.cs index a042803b4d..5b94bfe73f 100644 --- a/Orm/Xtensive.Orm/Orm/Upgrade/Hints/UpgradeHint.cs +++ b/Orm/Xtensive.Orm/Orm/Upgrade/Hints/UpgradeHint.cs @@ -22,14 +22,9 @@ public virtual bool Equals(UpgradeHint other) } /// - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - return false; - if (ReferenceEquals(this, obj)) - return true; - return obj is UpgradeHint otherHint && Equals(otherHint); - } + public override bool Equals(object obj) => + ReferenceEquals(this, obj) + || obj is UpgradeHint other && Equals(other); /// public override int GetHashCode() diff --git a/Orm/Xtensive.Orm/Orm/Upgrade/Internals/CatalogCloner.cs b/Orm/Xtensive.Orm/Orm/Upgrade/Internals/CatalogCloner.cs index 3780c71dba..99d216bebe 100644 --- a/Orm/Xtensive.Orm/Orm/Upgrade/Internals/CatalogCloner.cs +++ b/Orm/Xtensive.Orm/Orm/Upgrade/Internals/CatalogCloner.cs @@ -330,9 +330,9 @@ private void CloneTableConstraint(Table newTable, TableConstraint sourceConstrai } //foreign keys are handled by special method - var foreignKey = sourceConstraint as ForeignKey; - if (foreignKey!=null) + if (sourceConstraint is ForeignKey) { return; + } var uniqueConstraint = sourceConstraint as UniqueConstraint; if (uniqueConstraint!=null) { diff --git a/Orm/Xtensive.Orm/Orm/Upgrade/Internals/DomainModelConverter.cs b/Orm/Xtensive.Orm/Orm/Upgrade/Internals/DomainModelConverter.cs index 9a811904ae..5d7bf2d6f3 100644 --- a/Orm/Xtensive.Orm/Orm/Upgrade/Internals/DomainModelConverter.cs +++ b/Orm/Xtensive.Orm/Orm/Upgrade/Internals/DomainModelConverter.cs @@ -118,7 +118,7 @@ protected override IPathNode VisitDomainModel(DomainModel domainModel) if (type.Indexes.PrimaryIndex.IsVirtual) { Dictionary typeOrder = type.GetAncestors() .Append(type) - .Select((t, i) => new {Type = t, Index = i}) + .Select((t, i) => (Type: t, Index: i)) .ToDictionary(a => a.Type, a => a.Index); List realPrimaryIndexes = type.Indexes.RealPrimaryIndexes .OrderBy(index => typeOrder[index.ReflectedType]) diff --git a/Orm/Xtensive.Orm/Orm/Upgrade/Internals/HintGenerator.cs b/Orm/Xtensive.Orm/Orm/Upgrade/Internals/HintGenerator.cs index 859dfa15ac..550da7d369 100644 --- a/Orm/Xtensive.Orm/Orm/Upgrade/Internals/HintGenerator.cs +++ b/Orm/Xtensive.Orm/Orm/Upgrade/Internals/HintGenerator.cs @@ -373,7 +373,7 @@ from association in extractedModel.Associations // X.EntitySet, where X is in removedTypeAndAncestors, // connectorType.X must be cleaned up as well requiresInverseCleanup - select new {association, requiresInverseCleanup} + select (association, requiresInverseCleanup) ).ToList(); foreach (var pair in affectedAssociations) { var association = pair.association; diff --git a/Orm/Xtensive.Orm/Orm/Upgrade/Internals/Metadata/TypeMetadata.cs b/Orm/Xtensive.Orm/Orm/Upgrade/Internals/Metadata/TypeMetadata.cs index 3f9bd4238c..ded92925fe 100644 --- a/Orm/Xtensive.Orm/Orm/Upgrade/Internals/Metadata/TypeMetadata.cs +++ b/Orm/Xtensive.Orm/Orm/Upgrade/Internals/Metadata/TypeMetadata.cs @@ -1,6 +1,6 @@ -// Copyright (C) 2012 Xtensive LLC. -// All rights reserved. -// For conditions of distribution and use, see license. +// Copyright (C) 2012-2021 Xtensive LLC. +// This code is distributed under MIT license terms. +// See the License.txt file in the project root for more information. // Created by: Denis Krjuchkov // Created: 2012.02.16 @@ -9,16 +9,14 @@ namespace Xtensive.Orm.Upgrade { - internal sealed class TypeMetadata + internal readonly struct TypeMetadata { - public int Id { get; private set; } + public int Id { get; } - public string Name { get; set; } + public string Name { get; } - public override string ToString() - { - return string.Format(Strings.MetadataTypeFormat, Name, Id); - } + public override string ToString() => + string.Format(Strings.MetadataTypeFormat, Name, Id); // Constructors @@ -36,4 +34,4 @@ public TypeMetadata(int id, System.Type type) Name = type.GetFullName(); } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Upgrade/Internals/SchemaComparer.cs b/Orm/Xtensive.Orm/Orm/Upgrade/Internals/SchemaComparer.cs index a29078bac2..722b8bf2f1 100644 --- a/Orm/Xtensive.Orm/Orm/Upgrade/Internals/SchemaComparer.cs +++ b/Orm/Xtensive.Orm/Orm/Upgrade/Internals/SchemaComparer.cs @@ -38,7 +38,7 @@ internal static class SchemaComparer /// A current . /// Comparison result. public static SchemaComparisonResult Compare( - StorageModel sourceSchema, StorageModel targetSchema, + StorageModel sourceSchema, StorageModel targetSchema, HintSet schemaHints, SetSlim upgradeHints, SchemaUpgradeMode schemaUpgradeMode, DomainModel model, bool briefExceptionFormat, UpgradeStage upgradeStage) @@ -91,7 +91,7 @@ public static SchemaComparisonResult Compare( || sourceType.Type.ToNullable()!=targetType.Type.ToNullable(); }) .ToList(); - + var isCompatibleInLegacyMode = createTableActions.Count==0 @@ -296,4 +296,3 @@ private static SchemaComparisonStatus GetComparisonStatus(ICollection RewriteGenericTypeHints(IEnumerable /// Builds generic types mapping. /// - private List>>> BuildGenericTypeMapping(Dictionary renamedTypesLookup) + private List<(string, Type, List>)> BuildGenericTypeMapping(Dictionary renamedTypesLookup) { var oldGenericTypes = GetGenericTypes(extractedModel); var newGenericTypes = GetGenericTypes(domainModel); - var genericTypeMapping = new List>>>(); + var genericTypeMapping = new List<(string, Type, List>)>(); var newTypesLookup = newGenericTypes.GetClasses().ToDictionary(t => t.GetFullName()); foreach (var oldGenericDefName in oldGenericTypes.GetClasses()) { var newGenericDefType = GetNewType(oldGenericDefName, newTypesLookup, renamedTypesLookup); @@ -143,8 +143,7 @@ private List>>> BuildGenericTypeMa genericArgumentsMapping.Add(new Pair(oldGenericArgumentType, newGenericArgumentType)); } if (genericArgumentsMapping.Count == pair.Second.Length) { - genericTypeMapping.Add(new Triplet>>( - oldGenericDefName, newGenericDefType, genericArgumentsMapping)); + genericTypeMapping.Add((oldGenericDefName, newGenericDefType, genericArgumentsMapping)); } } } @@ -154,15 +153,15 @@ private List>>> BuildGenericTypeMa /// /// Builds for generic types. /// - private void BuildRenameHintsForGenericTypes(IList>>> genericTypeMapping, ICollection rewrittenHints) + private void BuildRenameHintsForGenericTypes(IList<(string, Type, List>)> genericTypeMapping, ICollection rewrittenHints) { foreach (var triplet in genericTypeMapping) { - var arrays = triplet.Third.SelectToArrays(pair => pair.First, pair => pair.Second); + var arrays = triplet.Item3.SelectToArrays(pair => pair.First, pair => pair.Second); var oldGenericArguments = arrays.First; var newGenericArguments = arrays.Second; - var oldTypeFullName = GetGenericTypeFullName(triplet.First, oldGenericArguments); - var newType = triplet.Second.MakeGenericType(newGenericArguments); + var oldTypeFullName = GetGenericTypeFullName(triplet.Item1, oldGenericArguments); + var newType = triplet.Item2.MakeGenericType(newGenericArguments); if (!oldTypeFullName.Equals(newType.GetFullName(), StringComparison.Ordinal)) { rewrittenHints.Add(new RenameTypeHint(oldTypeFullName, newType)); } @@ -174,28 +173,26 @@ private void BuildRenameHintsForGenericTypes(IList private void BuildRenameFieldHintsForGenericTypes( - IEnumerable>>> genericTypeMapping, + IEnumerable<(string, Type, List>)> genericTypeMapping, IEnumerable renameFieldHints, ICollection rewrittenHints) { var genericTypeDefLookup = ( from triplet in genericTypeMapping - group triplet by triplet.Second.GetGenericTypeDefinition() + group triplet by triplet.Item2.GetGenericTypeDefinition() into g - select new { Definition = g.Key, Instances = g.ToArray() } + select (Definition: g.Key, Instances: g.ToArray()) ).ToDictionary(g => g.Definition); // Build rename generic type field hints foreach (var hint in renameFieldHints) { var newGenericDefType = hint.TargetType; - var instanceGroup = genericTypeDefLookup.GetValueOrDefault(newGenericDefType); - if (instanceGroup == null) { - continue; - } - foreach (var triplet in instanceGroup.Instances) { - var newGenericArguments = triplet.Third.SelectToArray(pair => pair.Second); - rewrittenHints.Add(new RenameFieldHint(newGenericDefType.MakeGenericType(newGenericArguments), - hint.OldFieldName, hint.NewFieldName)); + if (genericTypeDefLookup.TryGetValue(newGenericDefType, out var instanceGroup)) { + foreach (var triplet in instanceGroup.Instances) { + var newGenericArguments = triplet.Item3.SelectToArray(pair => pair.Second); + rewrittenHints.Add(new RenameFieldHint(newGenericDefType.MakeGenericType(newGenericArguments), + hint.OldFieldName, hint.NewFieldName)); + } } } } diff --git a/Orm/Xtensive.Orm/Orm/Upgrade/SystemUpgradeHandler.cs b/Orm/Xtensive.Orm/Orm/Upgrade/SystemUpgradeHandler.cs index a001521c48..9bdb2802cb 100644 --- a/Orm/Xtensive.Orm/Orm/Upgrade/SystemUpgradeHandler.cs +++ b/Orm/Xtensive.Orm/Orm/Upgrade/SystemUpgradeHandler.cs @@ -237,7 +237,7 @@ private ExtensionMetadata GetPartialIndexes(Domain domain, IEnumerable var indexes = types .SelectMany(type => type.Indexes .Where(i => i.IsPartial && !i.IsVirtual && !i.IsAbstract) - .Select(i => new {Type = type, Index = i})) + .Select(i => (Type: type, Index: i))) .Select(item => new StoredPartialIndexFilterInfo { Database = item.Type.MappingDatabase, Schema = item.Type.MappingSchema, diff --git a/Orm/Xtensive.Orm/Orm/Upgrade/UpgradeHandler.cs b/Orm/Xtensive.Orm/Orm/Upgrade/UpgradeHandler.cs index b754dd3add..1b60ac3d86 100644 --- a/Orm/Xtensive.Orm/Orm/Upgrade/UpgradeHandler.cs +++ b/Orm/Xtensive.Orm/Orm/Upgrade/UpgradeHandler.cs @@ -346,7 +346,7 @@ where context.Configuration.Types.Contains(t) from t in registeredTypes let a = t.GetAttribute() where a!=null - select new {Type = t, Attribute = a}; + select (Type: t, Attribute: a); foreach (var r in recycledTypes) { var oldName = r.Attribute.OriginalName; @@ -378,7 +378,7 @@ from p in t.GetProperties(BindingFlags.DeclaredOnly let pa = p.GetAttribute() let ra = p.GetAttribute() where pa!=null && ra!=null - select new {Property = p, Attribute = ra}; + select (Property: p, Attribute: ra); foreach (var r in recycledProperties) { var oldName = r.Attribute.OriginalName; diff --git a/Orm/Xtensive.Orm/Sql/Model/SqlModelVisitor.cs b/Orm/Xtensive.Orm/Sql/Model/SqlModelVisitor.cs index bc5b238efc..9196ade659 100644 --- a/Orm/Xtensive.Orm/Sql/Model/SqlModelVisitor.cs +++ b/Orm/Xtensive.Orm/Sql/Model/SqlModelVisitor.cs @@ -1,6 +1,6 @@ -// Copyright (C) 2003-2010 Xtensive LLC. -// All rights reserved. -// For conditions of distribution and use, see license. +// Copyright (C) 2003-2021 Xtensive LLC. +// This code is distributed under MIT license terms. +// See the License.txt file in the project root for more information. // Created by: Ivan Galkin // Created: 2009.03.31 @@ -21,104 +21,41 @@ public abstract class SqlModelVisitor /// The node. /// Visit result. /// Node type is unknown. - protected virtual TResult Visit(Node node) - { - var characterSet = node as CharacterSet; - if (characterSet!=null) - return VisitCharacterSet(characterSet); - var collation = node as Collation; - if (collation!=null) - return VisitCollation(collation); - var temporaryTable = node as TemporaryTable; - if (temporaryTable!=null) - return VisitTemporaryTable(temporaryTable); - var table = node as Table; - if (table!=null) - return VisitTable(table); - var view = node as View; - if (view!=null) - return VisitView(view); - var dataTable = node as DataTable; - if (dataTable!=null) - return VisitDataTable(dataTable); - var tableColumn = node as TableColumn; - if (tableColumn!=null) - return VisitTableColumn(tableColumn); - var viewColumn = node as ViewColumn; - if (viewColumn!=null) - return VisitViewColumn(viewColumn); - var dataTableColumn = node as DataTableColumn; - if (dataTableColumn!=null) - return VisitDataTableColumn(dataTableColumn); - var domain = node as Domain; - if (domain!=null) - return VisitDomain(domain); - var ftIndex = node as FullTextIndex; - if (ftIndex != null) - return VisitFullTextIndex(ftIndex); - var index = node as Index; - if (index!=null) - return VisitIndex(index); - var indexColumn = node as IndexColumn; - if (indexColumn!=null) - return VisitIndexColumn(indexColumn); - var foreignKey = node as ForeignKey; - if (foreignKey!=null) - return VisitForeignKey(foreignKey); - var primaryKey = node as PrimaryKey; - if (primaryKey!=null) - return VisitPrimaryKey(primaryKey); - var uniqueConstraint = node as UniqueConstraint; - if (uniqueConstraint!=null) - return VisitUniqueConstraint(uniqueConstraint); - var checkConstraint = node as CheckConstraint; - if (checkConstraint!=null) - return VisitCheckConstraint(checkConstraint); - var domainConstraint = node as DomainConstraint; - if (domainConstraint!=null) - return VisitDomainConstraint(domainConstraint); - var constraint = node as Constraint; - if (constraint!=null) - return VisitConstraint(constraint); - var schema = node as Schema; - if (schema!=null) - return VisitSchema(schema); - var sequence = node as Sequence; - if (sequence!=null) - return VisitSequence(sequence); - var sequenceDescriptor = node as SequenceDescriptor; - if (sequenceDescriptor!=null) - return VisitSequenceDescriptor(sequenceDescriptor); - var catalog = node as Catalog; - if (catalog!=null) - return VisitCatalog(catalog); - var translation = node as Translation; - if (translation!=null) - return VisitTranslation(translation); - var hashPartition = node as HashPartition; - if (hashPartition!=null) - return VisitHashPartition(hashPartition); - var listPartition = node as ListPartition; - if (listPartition!=null) - return VisitListPartition(listPartition); - var rangePartition = node as RangePartition; - if (rangePartition!=null) - return VisitRangePartition(rangePartition); - var partition = node as Partition; - if (partition!=null) - return VisitPartition(partition); - var partitionDescriptor = node as PartitionDescriptor; - if (partitionDescriptor!=null) - return VisitPartitionDescriptor(partitionDescriptor); - var partitionFunction = node as PartitionFunction; - if (partitionFunction!=null) - return VisitPartitionFunction(partitionFunction); - var partitionSchema = node as PartitionSchema; - if (partitionSchema!=null) - return VisitPartitionSchema(partitionSchema); - - throw new ArgumentException(Strings.ExNodeTypeIsUnknown, "node"); - } + protected virtual TResult Visit(Node node) => + node switch { + CharacterSet characterSet => VisitCharacterSet(characterSet), + Collation collation => VisitCollation(collation), + TemporaryTable temporaryTable => VisitTemporaryTable(temporaryTable), + Table table => VisitTable(table), + View view => VisitView(view), + DataTable dataTable => VisitDataTable(dataTable), + TableColumn tableColumn => VisitTableColumn(tableColumn), + ViewColumn viewColumn => VisitViewColumn(viewColumn), + DataTableColumn dataTableColumn => VisitDataTableColumn(dataTableColumn), + Domain domain => VisitDomain(domain), + FullTextIndex ftIndex => VisitFullTextIndex(ftIndex), + Index index => VisitIndex(index), + IndexColumn indexColumn => VisitIndexColumn(indexColumn), + ForeignKey foreignKey => VisitForeignKey(foreignKey), + PrimaryKey primaryKey => VisitPrimaryKey(primaryKey), + UniqueConstraint uniqueConstraint => VisitUniqueConstraint(uniqueConstraint), + CheckConstraint checkConstraint => VisitCheckConstraint(checkConstraint), + DomainConstraint domainConstraint => VisitDomainConstraint(domainConstraint), + Constraint constraint => VisitConstraint(constraint), + Schema schema => VisitSchema(schema), + Sequence sequence => VisitSequence(sequence), + SequenceDescriptor sequenceDescriptor => VisitSequenceDescriptor(sequenceDescriptor), + Catalog catalog => VisitCatalog(catalog), + Translation translation => VisitTranslation(translation), + HashPartition hashPartition => VisitHashPartition(hashPartition), + ListPartition listPartition => VisitListPartition(listPartition), + RangePartition rangePartition => VisitRangePartition(rangePartition), + Partition partition => VisitPartition(partition), + PartitionDescriptor partitionDescriptor => VisitPartitionDescriptor(partitionDescriptor), + PartitionFunction partitionFunction => VisitPartitionFunction(partitionFunction), + PartitionSchema partitionSchema => VisitPartitionSchema(partitionSchema), + _ => throw new ArgumentException(Strings.ExNodeTypeIsUnknown, "node") + }; /// /// Visits unique constraint. diff --git a/Orm/Xtensive.Orm/Sql/SqlType.cs b/Orm/Xtensive.Orm/Sql/SqlType.cs index a932533e7e..9cba773976 100644 --- a/Orm/Xtensive.Orm/Sql/SqlType.cs +++ b/Orm/Xtensive.Orm/Sql/SqlType.cs @@ -189,12 +189,8 @@ public bool Equals(SqlType other) return string.Equals(Name, other.Name, StringComparison.Ordinal); } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - return false; - return obj is SqlType && Equals((SqlType) obj); - } + public override bool Equals(object obj) => + obj is SqlType other && Equals(other); public override int GetHashCode() {