diff --git a/Orm/Xtensive.Orm/Collections/Deque.cs b/Orm/Xtensive.Orm/Collections/Deque.cs
deleted file mode 100644
index 80d4c2c15..000000000
--- a/Orm/Xtensive.Orm/Collections/Deque.cs
+++ /dev/null
@@ -1,663 +0,0 @@
-// Copyright (C) 2003-2010 Xtensive LLC.
-// All rights reserved.
-// For conditions of distribution and use, see license.
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.Serialization;
-using System.Security;
-using System.Security.Permissions;
-using Xtensive.Comparison;
-using Xtensive.Core;
-
-
-
-namespace Xtensive.Collections
-{
- ///
- /// Double-ended queue.
- ///
- /// The type of queued elements.
- ///
- ///
- /// it is a sequence that supports random access to its elements,
- /// constant time of insertion and removal of elements at the both ends of the sequence,
- /// and linear time of insertion and removal of elements in the middle.
- ///
- ///
- /// The capacity of a is the number of elements the can hold.
- /// In this implementation, the default initial capacity for a is 16;
- /// however, that default might change in future versions.
- ///
- ///
- /// As elements are added to a , the capacity is automatically increased as required
- /// by reallocating the internal array. The capacity can be decreased by calling .
- ///
- ///
- /// The growth factor is the number by which the current capacity is multiplied when a greater capacity
- /// is required. The growth factor is determined when the is constructed.
- ///
- ///
- /// accepts a
- /// as a valid value for reference types and allows duplicate elements.
- ///
- ///
- [Serializable]
- [DebuggerDisplay("Count = {Count}")]
- public class Deque : IDeque,
- ISerializable,
- ICloneable
- {
- private const int minimalCapacity = 16;
- private const float defaultGrowFactor = 1.4f;
- private const float trimThresholdFactor = 0.9f;
-
- private T[] items; // Actual data buffer
- private int headPos; // Heading free element position
- private int tailPos; // Taililg free element position
- private int count; // Actual number of stored elements
- private int version; // Version to detect consistency while enumeration executes
- private readonly float growFactor = defaultGrowFactor;
-
- ///
- public int Count
- {
- [DebuggerStepThrough]
- get { return count; }
- }
-
- ///
- public T this[int index] {
- get {
- ArgumentValidator.EnsureArgumentIsInRange(index, 0, count-1, "index");
- return items[ConvertToBufferIndex(index)];
- }
- set {
- ArgumentValidator.EnsureArgumentIsInRange(index, 0, count-1, "index");
- items[ConvertToBufferIndex(index)] = value;
- version++;
- }
- }
-
- #region Capacity, TrimExcess
-
- ///
- public int Capacity
- {
- get { return items.Length; }
- set
- {
- if (value!=items.Length) {
- if (value < count)
- throw new ArgumentOutOfRangeException("value", Strings.ExSpecifiedCapacityIsLessThenCollectionCount);
- if (value > minimalCapacity) {
- T[] newItems = new T[value];
- InnerCopyTo(newItems, 0);
- headPos = value - 1;
- tailPos = count;
- items = newItems;
- version++;
- }
- else {
- items = new T[minimalCapacity];
- headPos = minimalCapacity - 1;
- tailPos = 0;
- }
- }
- }
- }
-
- ///
- public void TrimExcess()
- {
- int trimThreshold = (int)(items.Length*trimThresholdFactor);
- if (count < trimThreshold)
- Capacity = count;
- }
-
- #endregion
-
- #region Head, Tail, Add\Extract Head\Tail
-
- ///
- public T Head {
- get {
- if (count==0)
- throw Exceptions.CollectionIsEmpty(null);
- return items[(items.Length - headPos==1 ? 0 : headPos + 1)];
- }
- }
-
- ///
- public T HeadOrDefault {
- get {
- return count==0 ? default(T) : items[(items.Length - headPos==1 ? 0 : headPos + 1)];
- }
- }
-
- ///
- public T Tail {
- get {
- if (count==0)
- throw Exceptions.CollectionIsEmpty(null);
- return items[(tailPos==0 ? items.Length : tailPos) - 1];
- }
- }
-
- ///
- public T TailOrDefault {
- get {
- return count==0 ? default(T) : items[(tailPos==0 ? items.Length : tailPos) - 1];
- }
- }
-
- ///
- public void AddHead(T element)
- {
- if (count==items.Length)
- EnsureCapacity(count + 1);
-
- count++;
- items[headPos] = element;
-
- // Shift to the "previous free" position
- if ((--headPos)==-1) {
- // If count < buffer.Length then all elements in the interval
- // [0 ... buffer.Length - count] are "free"
- headPos += items.Length;
- }
- version++;
- }
-
- ///
- public void AddTail(T element)
- {
- if (count==items.Length)
- EnsureCapacity(count + 1);
-
- count++;
- items[tailPos] = element;
-
- // Shift to "previous free" position
- if ((++tailPos)==items.Length) {
- // If count < buffer.Length then all elements in the interval
- // [count - 1 ... buffer.Length - 1] are "free"
- tailPos = 0;
- }
- version++;
- }
-
- ///
- public T ExtractHead()
- {
- if (count==0)
- throw Exceptions.CollectionIsEmpty(null);
-
- // Shift to the "head element" position
- if ((++headPos)==items.Length)
- headPos = 0;
-
- // Extract element
- T result = items[headPos];
- items[headPos] = default(T);
- count--;
- version++;
-
- return result;
- }
-
- ///
- public T ExtractTail()
- {
- if (count==0)
- throw Exceptions.CollectionIsEmpty(null);
-
- // Shift to the "tail element" position
- if ((--tailPos)==-1)
- tailPos += items.Length;
-
- // Extract element
- T result = items[tailPos];
- items[tailPos] = default(T);
- count--;
- version++;
-
- return result;
- }
-
- #endregion
-
- #region IndexOf, Contains
-
- ///
- public int IndexOf(T item)
- {
- Predicate criterion = delegate(T innerItem) {
- return AdvancedComparerStruct.System.Equals(innerItem, item);
- };
- int headIndex = headPos + 1;
- if (headIndex==items.Length)
- headIndex = 0;
- if (tailPos==0 || tailPos - headIndex > 0)
- return ConvertToListIndex(Array.FindIndex(items, headIndex, count, criterion));
- else {
- int itemIndex = -1;
- if (headIndex > 0)
- itemIndex = Array.FindIndex(items, headIndex, criterion);
- if (itemIndex < 0)
- itemIndex = Array.FindIndex(items, 0, tailPos, criterion);
- return ConvertToListIndex(itemIndex);
- }
- }
-
- ///
- public bool Contains(T item)
- {
- Predicate criterion = delegate(T innerItem) { return AdvancedComparerStruct.System.Equals(innerItem, item); };
- int headIndex = headPos + 1;
- if (tailPos - headIndex > 0)
- return Array.FindIndex(items, headIndex, count, criterion) >= 0;
- else
- return (tailPos > 0 && Array.FindIndex(items, 0, tailPos, criterion) >= 0) ||
- (headIndex < items.Length && Array.FindIndex(items, headIndex, criterion) >= 0);
- }
-
- #endregion
-
- #region CopyTo
-
- ///
- public void CopyTo(T[] array, int arrayIndex)
- {
- ArgumentNullException.ThrowIfNull(array);
- array.EnsureIndexIsValid(arrayIndex);
-
- if (arrayIndex + count > array.Length)
- throw new ArgumentException(Strings.ExDestionationArrayIsTooSmall, "array");
- InnerCopyTo(array, arrayIndex);
- }
-
- ///
- public void CopyTo(Array array, int index)
- {
- ArgumentNullException.ThrowIfNull(array);
- array.EnsureIndexIsValid(index);
-
- if (array.Rank!=1)
- throw new ArgumentException(Strings.ExArrayIsMultidimensional, "array");
- if (array.GetLowerBound(0)!=0)
- throw new ArgumentException(Strings.ExArrayDoesNotHaveZeroBasedIndexing, "array");
- if (index + count > array.Length)
- throw new ArgumentException(Strings.ExDestionationArrayIsTooSmall, "array");
- InnerCopyTo(array, index);
- }
-
- #endregion
-
- #region Insert, RemoveAt, Remove, RemoveRange, Clear
-
- ///
- public void Insert(int index, T item)
- {
- ArgumentValidator.EnsureArgumentIsInRange(index, 0, count, "index");
-
- if (count==items.Length)
- EnsureCapacity(count + 1);
-
- int bufferIndex = ConvertToBufferIndex(index);
- int headIndex = headPos + 1;
- if (headIndex==items.Length)
- headIndex = 0;
- if (bufferIndex==tailPos)
- AddTail(item);
- else if (bufferIndex==headIndex)
- AddHead(item);
- else if (bufferIndex < tailPos) {
- int dataToMoveLength = tailPos - bufferIndex;
- Array.Copy(items, bufferIndex, items, bufferIndex + 1, dataToMoveLength);
- items[bufferIndex] = item;
- // Shift to "next free" position
- if ((++tailPos)==items.Length)
- tailPos = 0;
- count++;
- version++;
- }
- else if (bufferIndex > headIndex) {
- int dataToMoveLength = bufferIndex - headIndex;
- Array.Copy(items, headPos + 1, items, headPos, dataToMoveLength);
- items[bufferIndex - 1] = item;
- // Shift to "previous free" position
- if ((--headPos)==-1)
- headPos += items.Length;
- count++;
- version++;
- }
- else {
- throw Exceptions.InternalError("Deque.Insert: Wrong buffer index detected.", CoreLog.Instance);
- }
- }
-
- ///
- public void RemoveAt(int index)
- {
- ArgumentValidator.EnsureArgumentIsInRange(index, 0, count-1, "index");
-
- int bufferIndex = ConvertToBufferIndex(index);
- if (tailPos - bufferIndex==1)
- ExtractTail();
- else if (bufferIndex - headPos==1)
- ExtractHead();
- else if (bufferIndex > headPos) {
- int dataToMoveLength = bufferIndex - headPos - 1;
- // Shift to the "tail element" position
- headPos++;
- Array.Copy(items, headPos, items, headPos + 1, dataToMoveLength);
- items[headPos] = default(T);
- count--;
- version++;
- }
- else if (bufferIndex < tailPos) {
- int dataToMoveLength = tailPos - bufferIndex - 1;
- // Shift to the "head element" position
- tailPos--;
- Array.Copy(items, bufferIndex + 1, items, bufferIndex, dataToMoveLength);
- items[tailPos] = default(T);
- count--;
- version++;
- }
- else {
- throw Exceptions.InternalError("Deque.RemoveAt: Wrong buffer index detected.", CoreLog.Instance);
- }
- }
-
- ///
- public bool Remove(T item)
- {
- int itemIndex = IndexOf(item);
- if (itemIndex < 0)
- return false;
- RemoveAt(itemIndex);
- version++;
- return true;
- }
-
- ///
- public void RemoveRange(int index, int count)
- {
- ArgumentValidator.EnsureArgumentIsInRange(index, 0, this.count-1, "index");
- ArgumentValidator.EnsureArgumentIsInRange(count, 0, this.count-index, "count");
-
- if (count < 0 || (count > this.count - index))
- throw new ArgumentOutOfRangeException("count");
-
- int bufferIndex = ConvertToBufferIndex(index);
- if (this.count > 0) {
- int tailLength = this.count - count - index;
- if (tailLength > 0) {
- if (tailPos - bufferIndex > 0) {
- Array.Copy(items, bufferIndex + count, items, bufferIndex, this.count - count - index);
- }
- else {
- int endBufferIndex = ConvertToBufferIndex(index + count);
- int firstChunkLength = Math.Min(count, items.Length - bufferIndex);
- int secondChunkLength = Math.Max(0, count - firstChunkLength);
- if (firstChunkLength > 0) {
- Array.Copy(items, endBufferIndex, items, bufferIndex, Math.Min(firstChunkLength, tailLength));
- }
- if (secondChunkLength > 0 && tailLength > firstChunkLength) {
- Array.Copy(items, endBufferIndex + firstChunkLength, items, 0, tailLength - firstChunkLength);
- }
- }
- }
- int startFillPosition = ConvertToBufferIndex(this.count - count);
- int newTail = startFillPosition;
- if (tailPos < startFillPosition) {
- for (int i = startFillPosition; i < items.Length; i++)
- items[i] = default(T);
- startFillPosition = 0;
- }
- for (int i = startFillPosition; i < tailPos; i++)
- items[i] = default(T);
-
- tailPos = newTail;
- this.count -= count;
- }
- }
-
- ///
- public void Clear()
- {
- int capacity = items.Length;
- Array.Clear(items, 0, capacity);
- headPos = capacity - 1;
- tailPos = 0;
- count = 0;
- version++;
- }
-
- #endregion
-
- #region ICollection, ICollection members
-
- ///
- void ICollection.Add(T item)
- {
- AddTail(item);
- }
-
- ///
- bool ICollection.IsReadOnly
- {
- get { return false; }
- }
-
- #endregion
-
- #region IEnumerable, IEnumerable members
-
- ///
- [DebuggerStepThrough]
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- ///
- public IEnumerator GetEnumerator()
- {
- int itemIndex = headPos;
- int itemCount = count;
- int length = items.Length;
- int oldVersion = version;
- while (itemCount-- > 0) {
- if (version!=oldVersion)
- throw Exceptions.CollectionHasBeenChanged(null);
- if ((++itemIndex)==length)
- itemIndex = 0;
- yield return items[itemIndex];
- }
- }
-
- #endregion
-
- #region ICloneable members
-
- ///
- /// Creates a shallow copy of the .
- ///
- /// A shallow copy of the .
- ///
- ///
- /// A shallow copy of a collection copies only the elements of the collection,
- /// whether they are reference types or value types, but it does not copy
- /// the objects that the references refer to. The references in the new collection
- /// point to the same objects that the references in the original collection point to.
- ///
- ///
- /// In contrast, a deep copy of a collection copies the elements and
- /// everything directly or indirectly referenced by the elements.
- ///
- ///
- /// This method is an O(n) operation, where n is .
- ///
- ///
- public virtual object Clone()
- {
- return new Deque(this);
- }
-
- #endregion
-
-
- #region Private \ internal methods
-
- private void InnerCopyTo(Array array, int arrayIndex)
- {
- int headIndex = headPos + 1;
- if (count > 0) {
- if (tailPos - headIndex > 0)
- Array.Copy(items, headIndex, array, arrayIndex, count);
- else {
- int headPartLength = items.Length - headIndex;
- if (headPartLength > 0)
- Array.Copy(items, headIndex, array, arrayIndex, headPartLength);
- Array.Copy(items, 0, array, arrayIndex + headPartLength, count - headPartLength);
- }
- }
- }
-
- private int ConvertToListIndex(int bufferIndex)
- {
- if (bufferIndex < 0)
- return bufferIndex;
- return (bufferIndex > headPos ? 0 : items.Length) + bufferIndex - headPos - 1;
- }
-
- private int ConvertToBufferIndex(int listIndex)
- {
- if (listIndex < 0)
- return listIndex;
- int bufferIndex = headPos + listIndex + 1;
- return bufferIndex - (bufferIndex >= items.Length ? items.Length : 0);
- }
-
- private void EnsureCapacity(int requiredCapacity)
- {
- int currentCapacity = items.Length;
- if (currentCapacity < requiredCapacity) {
- int newCapacity = currentCapacity==0
- ? minimalCapacity
- : Convert.ToInt32(currentCapacity*growFactor);
- if (newCapacity < requiredCapacity)
- newCapacity = requiredCapacity;
- Capacity = newCapacity;
- }
- }
-
- #endregion
-
-
- // Constructors
-
- private Deque(Deque source)
- {
- count = source.count;
- items = new T[count];
- source.InnerCopyTo(items, 0);
- headPos = count - 1;
- tailPos = 0;
- growFactor = source.growFactor;
- }
-
- ///
- /// Initializes a new instance of this type.
- ///
- public Deque()
- : this(minimalCapacity)
- {
- }
-
- ///
- /// Initializes a new instance of this type.
- ///
- /// The initial property value.
- public Deque(int initialCapacity)
- {
- if (initialCapacity < minimalCapacity)
- initialCapacity = minimalCapacity;
- items = new T[initialCapacity];
- headPos = initialCapacity - 1;
- tailPos = 0;
- count = 0;
- }
-
- ///
- /// Initializes a new instance of this type.
- ///
- /// The initial property value.
- /// The factor by which the capacity of the is expanded.
- public Deque(int initialCapacity, float growFactor)
- : this(initialCapacity)
- {
- this.growFactor = growFactor;
- }
-
- ///
- /// Initializes a new instance of this type.
- ///
- /// The initial contents of the .
- public Deque(IEnumerable source)
- {
- items = new List(source).ToArray();
- headPos = -1;
- tailPos = items.Length;
- count = items.Length;
- EnsureCapacity(Capacity);
- }
-
- ///
- /// Initializes a new instance of this type.
- ///
- /// The initial contents of the .
- /// The factor by which the capacity of the is expanded.
- public Deque(IEnumerable source, float growFactor)
- : this(source)
- {
- this.growFactor = growFactor;
- }
-
- #region ISerializable Members
-
- ///
- /// Serializes instance of this type.
- ///
- ///
- ///
- [SecurityCritical]
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- T[] arrItems = new T[count];
- InnerCopyTo(arrItems, 0);
- info.AddValue("Items", arrItems);
- info.AddValue("GrowFactor", growFactor);
- }
-
- ///
- /// Deserializes instance of this type.
- ///
- ///
- ///
- protected Deque(SerializationInfo info, StreamingContext context)
- {
- items = (T[])info.GetValue("Items", typeof (T[]));
- growFactor = info.GetSingle("GrowFactor");
- count = items.Length;
- headPos = count - 1;
- tailPos = count - 1;
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/Orm/Xtensive.Orm/Collections/Interfaces/IDeque.cs b/Orm/Xtensive.Orm/Collections/Interfaces/IDeque.cs
deleted file mode 100644
index 324a6f189..000000000
--- a/Orm/Xtensive.Orm/Collections/Interfaces/IDeque.cs
+++ /dev/null
@@ -1,153 +0,0 @@
-// Copyright (C) 2003-2010 Xtensive LLC.
-// All rights reserved.
-// For conditions of distribution and use, see license.
-// Created by: Aleksey Gamzov
-// Created: 2008.01.07
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-
-namespace Xtensive.Collections
-{
- ///
- /// Double-ended queue contract.
- ///
- /// The type of queued elements.
- public interface IDeque : IList
- {
- ///
- /// Gets or sets the size of an internal array.
- ///
- ///
- /// Indicates the size of an internal array.
- /// The minimally allowed value which is also the default one is 16.
- ///
- ///
- /// As elements are added to a , the capacity is automatically increased as required
- /// by reallocating the internal array. The capacity can be decreased by calling .
- ///
- int Capacity { get; set; }
-
- ///
- /// Sets the capacity to the actual number of elements in the ,
- /// if that number is less than 90 percent of current capacity.
- ///
- ///
- /// This method can be used to minimize a collection's memory overhead
- /// if no new elements will be added to the collection.
- ///
- /// The cost of reallocating and copying a large can be considerable, however,
- /// so the method does nothing if the deque is at more than 90 percent of capacity.
- /// This avoids incurring a large reallocation cost for a relatively small gain.
- ///
- ///
- /// This method is an O(n) operation, where n is .
- ///
- /// To reset a to its initial state, call the method
- /// before calling method.
- /// Trimming an empty sets the capacity of the
- /// to the default capacity.
- ///
- void TrimExcess();
-
- ///
- /// Gets head element in the .
- ///
- T Head { get; }
-
- ///
- /// Gets head element in the , or , if deque is empty.
- ///
- T HeadOrDefault { get; }
-
- ///
- /// Gets tail element in the .
- ///
- T Tail { get; }
-
- ///
- /// Gets tail element in the , or , if deque is empty.
- ///
- T TailOrDefault { get; }
-
- ///
- /// Adds to the head.
- ///
- ///
- /// The element to add to the .
- /// The value can be a for reference types.
- ///
- ///
- ///
- /// If already equals the ,
- /// the of the is increased by
- /// automatically reallocating the internal array, and the existing elements
- /// are copied to the new array before the new element is added.
- ///
- ///
- /// If is less than the of the internal array,
- /// this method is an O(1) operation.
- /// If the internal array needs to be reallocated to accommodate the new element,
- /// this method becomes an O(n) operation, where n is .
- ///
- ///
- void AddHead(T element);
-
- ///
- /// Adds to the tail.
- ///
- ///
- /// The element to add to the .
- /// The value can be a for reference types.
- ///
- ///
- ///
- /// If already equals the ,
- /// the of the is increased by
- /// automatically reallocating the internal array, and the existing elements
- /// are copied to the new array before the new element is added.
- ///
- ///
- /// If is less than the of the internal array,
- /// this method is an O(1) operation.
- /// If the internal array needs to be reallocated to accommodate the new element,
- /// this method becomes an O(n) operation, where n is .
- ///
- ///
- void AddTail(T element);
-
- ///
- /// Removes and returns the element at the head of the .
- ///
- /// The element that is removed from the head of the .
- /// The is empty.
- ///
- /// This method is an O(1) operation.
- ///
- T ExtractHead();
-
- ///
- /// Removes and returns the element at the tail of the .
- ///
- /// The element that is removed from the tail of the .
- /// The is empty.
- ///
- /// This method is an O(1) operation.
- ///
- T ExtractTail();
-
- ///
- /// Removes a range of items at the given index in the Deque. All items at indexes
- /// greater than move down indices
- /// in the Deque.
- ///
- /// The index in the list to remove the range at. The
- /// first item in the list has index 0.
- /// The number of items to remove.
- /// is
- /// less than zero or greater than or equal to Count, or is less than zero
- /// or too large.
- void RemoveRange(int index, int count);
- }
-}
\ No newline at end of file
diff --git a/Orm/Xtensive.Orm/Orm/Internals/ReferentialIntegrity/RemovalContext.cs b/Orm/Xtensive.Orm/Orm/Internals/ReferentialIntegrity/RemovalContext.cs
index f44162d7b..9c050a3ad 100644
--- a/Orm/Xtensive.Orm/Orm/Internals/ReferentialIntegrity/RemovalContext.cs
+++ b/Orm/Xtensive.Orm/Orm/Internals/ReferentialIntegrity/RemovalContext.cs
@@ -144,7 +144,7 @@ public void Dispose()
processor.Context = parent;
}
-
+
// Constructors
public RemovalContext(RemovalProcessor processor)
@@ -153,4 +153,4 @@ public RemovalContext(RemovalProcessor processor)
parent = processor.Context;
}
}
-}
\ No newline at end of file
+}
diff --git a/Orm/Xtensive.Orm/Orm/Operations/OperationRegistry.cs b/Orm/Xtensive.Orm/Orm/Operations/OperationRegistry.cs
index 9c2c82d0b..9012a2e8e 100644
--- a/Orm/Xtensive.Orm/Orm/Operations/OperationRegistry.cs
+++ b/Orm/Xtensive.Orm/Orm/Operations/OperationRegistry.cs
@@ -4,9 +4,6 @@
// Created by: Alex Yakunin
// Created: 2010.08.04
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
using Xtensive.Core;
namespace Xtensive.Orm.Operations
@@ -14,7 +11,7 @@ namespace Xtensive.Orm.Operations
///
/// Operation registry for type.
///
- public sealed class OperationRegistry
+ internal sealed class OperationRegistry : List
{
public readonly struct SystemOperationRegistrationScope : IDisposable
{
@@ -32,17 +29,18 @@ internal SystemOperationRegistrationScope(OperationRegistry registry, bool enabl
}
private readonly ICompletableScope blockingScope;
- private readonly Collections.Deque scopes = new();
private bool isOperationRegistrationEnabled = true;
private bool isUndoOperationRegistrationEnabled = true;
///
/// Gets the session this instance is bound to.
///
- internal Session Session { get; private set; }
+ internal Session Session { get; }
#region IsXxx properties
+ private List scopes => this;
+
///
/// Indicates whether operation logging is enabled.
/// implicitly turns this option off;
@@ -61,21 +59,14 @@ public bool IsRegistrationEnabled {
/// Gets a value indicating whether this instance can register operation
/// using method.
///
- public bool CanRegisterOperation {
- get {
- var scope = scopes.TailOrDefault;
- return scope!=null && scope is OperationRegistrationScope;
- }
- }
+ public bool CanRegisterOperation => scopes.LastOrDefault() is OperationRegistrationScope;
///
/// Gets a value indicating whether this instance is registering operation now,
/// i.e. method was invoked, but the
/// scope isn't closed yet.
///
- public bool IsRegisteringOperation {
- get { return scopes.Count!=0; }
- }
+ public bool IsRegisteringOperation => scopes.Count != 0;
internal bool IsOutermostOperationRegistrationEnabled {
get {
@@ -203,13 +194,8 @@ public void RegisterUndoOperation(Operation operation)
/// The entity identifier.
/// indicates identifier must be assigned automatically
/// as sequential number inside the current operation context.
- public void RegisterEntityIdentifier(Key key, string identifier)
- {
- var scope = scopes.HeadOrDefault as OperationRegistrationScope;
- if (scope==null)
- return;
- scope.RegisterEntityIdentifier(key, identifier);
- }
+ public void RegisterEntityIdentifier(Key key, string identifier) =>
+ (scopes.FirstOrDefault() as OperationRegistrationScope)?.RegisterEntityIdentifier(key, identifier);
///
/// Temporarily disables undo operation logging.
@@ -374,10 +360,7 @@ internal void NotifyUndoOperation(IOperation operation)
#region Private \ internal methods
- internal ICompletableScope GetCurrentScope()
- {
- return scopes.TailOrDefault;
- }
+ internal ICompletableScope GetCurrentScope() => scopes.LastOrDefault();
private OperationRegistrationScope GetCurrentOperationRegistrationScope()
{
@@ -390,39 +373,34 @@ private OperationRegistrationScope GetCurrentOperationRegistrationScope()
private OperationRegistrationScope GetCurrentOrParentOperationRegistrationScope()
{
var scope = GetCurrentScope();
- if (scope==null)
+ if (scope == null)
return null;
- var result = scope as OperationRegistrationScope;
- if (result!=null)
+ if (scope is OperationRegistrationScope result)
return result;
- var list = new ICompletableScope[scopes.Count];
- scopes.CopyTo(list, 0);
- for (int i = list.Length - 2; i>=0; i--) {
- result = list[i] as OperationRegistrationScope;
- if (result!=null)
- return result;
+ for (int i = scopes.Count - 1; i-- > 0;) {
+ if (scopes[i] is OperationRegistrationScope result2)
+ return result2;
}
throw new InvalidOperationException(Strings.ExNoOperationRegistrationScope);
}
internal ICompletableScope SetCurrentScope(ICompletableScope scope)
{
- scopes.AddTail(scope);
+ scopes.Add(scope);
return scope;
}
internal void RemoveCurrentScope(ICompletableScope scope)
{
- if (scopes.TailOrDefault!=scope)
+ if (scopes.LastOrDefault() != scope)
throw new InvalidOperationException(Strings.ExInvalidScopeDisposalOrder);
- scopes.ExtractTail();
+ scopes.RemoveAt(scopes.Count - 1);
}
- internal long GetNextIdentifier()
- {
- var scope = scopes.HeadOrDefault as OperationRegistrationScope;
- return scope==null ? -1 : scope.CurrentIdentifier++;
- }
+ internal long GetNextIdentifier() =>
+ scopes.FirstOrDefault() is OperationRegistrationScope scope
+ ? scope.CurrentIdentifier++
+ : -1;
#endregion
@@ -435,4 +413,4 @@ internal OperationRegistry(Session session)
blockingScope = new BlockingOperationRegistrationScope(this);
}
}
-}
\ No newline at end of file
+}
diff --git a/Orm/Xtensive.Orm/Orm/Session.cs b/Orm/Xtensive.Orm/Orm/Session.cs
index 4ffd89da4..3ebe609fa 100644
--- a/Orm/Xtensive.Orm/Orm/Session.cs
+++ b/Orm/Xtensive.Orm/Orm/Session.cs
@@ -141,7 +141,7 @@ internal bool LazyKeyGenerationIsEnabled
///
/// Gets the operations registry of this .
///
- public OperationRegistry Operations { get; private set; }
+ internal OperationRegistry Operations { get; private set; }
///
/// Gets or sets timeout for all s that