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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Orm/Xtensive.Orm/Collections/CollectionBaseSlim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ IEnumerator IEnumerable.GetEnumerator()
/// <inheritdoc/>
public virtual void Add(TItem item)
{
this.EnsureNotLocked();
EnsureNotLocked();
items.Add(item);
}

Expand All @@ -88,21 +88,21 @@ public virtual void Add(TItem item)
/// <exception cref="T:System.ArgumentNullException">collection is null.</exception>
public virtual void AddRange(IEnumerable<TItem> collection)
{
this.EnsureNotLocked();
EnsureNotLocked();
items.AddRange(collection);
}

/// <inheritdoc/>
public virtual bool Remove(TItem item)
{
this.EnsureNotLocked();
EnsureNotLocked();
return items.Remove(item);
}

/// <inheritdoc/>
public virtual void Clear()
{
this.EnsureNotLocked();
EnsureNotLocked();
items.Clear();
}

Expand Down
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm/Collections/ExtensionCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void Set<T>(T value)
/// <exception cref="ArgumentException">Wrong arguments.</exception>
public void Set(Type extensionType, object value)
{
this.EnsureNotLocked();
EnsureNotLocked();
ArgumentValidator.EnsureArgumentNotNull(extensionType, "extensionType");
if (extensionType.IsValueType)
throw new ArgumentException(string.Format(
Expand All @@ -87,7 +87,7 @@ public void Set(Type extensionType, object value)
/// <inheritdoc/>
public void Clear()
{
this.EnsureNotLocked();
EnsureNotLocked();
extensions = null;
}

Expand Down
8 changes: 4 additions & 4 deletions Orm/Xtensive.Orm/Collections/FlagCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public bool ContainsKey(TKey key)
/// <inheritdoc/>
public void Add(TKey key, TFlag flag)
{
this.EnsureNotLocked();
EnsureNotLocked();
if (keys.Contains(key))
throw new ArgumentException("key", Strings.ExCollectionAlreadyContainsSpecifiedItem);
if (keys.Count >= MaxItemCount)
Expand All @@ -91,7 +91,7 @@ public virtual void Add(TKey key)
public bool Remove(TKey key)
{
ArgumentValidator.EnsureArgumentIsNotDefault(key, "key");
this.EnsureNotLocked();
EnsureNotLocked();
int index = keys.IndexOf(key);
if (index < 0)
return false;
Expand Down Expand Up @@ -130,7 +130,7 @@ public TFlag this[TKey key]
set
{
ArgumentValidator.EnsureArgumentIsNotDefault(key, "key");
this.EnsureNotLocked();
EnsureNotLocked();
int index = keys.IndexOf(key);
if (index < 0)
Add(key, value);
Expand Down Expand Up @@ -191,7 +191,7 @@ public void Add(KeyValuePair<TKey, TFlag> item)
/// <inheritdoc/>
public void Clear()
{
this.EnsureNotLocked();
EnsureNotLocked();
keys.Clear();
flags = new BitVector32(0);
}
Expand Down
10 changes: 5 additions & 5 deletions Orm/Xtensive.Orm/Collections/TypeRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public bool Contains(Type type)
/// <param name="type">The type to register.</param>
public void Register(Type type)
{
this.EnsureNotLocked();
EnsureNotLocked();
ArgumentValidator.EnsureArgumentNotNull(type, "type");
if (!isProcessingPendingActions)
Register(new TypeRegistration(type));
Expand All @@ -78,7 +78,7 @@ public void Register(Type type)
/// <exception cref="ArgumentNullException">When <paramref name="assembly"/> is null.</exception>
public void Register(Assembly assembly)
{
this.EnsureNotLocked();
EnsureNotLocked();
ArgumentValidator.EnsureArgumentNotNull(assembly, "assembly");
Register(new TypeRegistration(assembly));
}
Expand All @@ -95,7 +95,7 @@ public void Register(Assembly assembly)
/// or <paramref name="namespace"/> is empty string.</exception>
public void Register(Assembly assembly, string @namespace)
{
this.EnsureNotLocked();
EnsureNotLocked();
ArgumentValidator.EnsureArgumentNotNull(assembly, "assembly");
ArgumentValidator.EnsureArgumentNotNullOrEmpty(@namespace, "@namespace");
Register(new TypeRegistration(assembly, @namespace));
Expand All @@ -109,7 +109,7 @@ public void Register(Assembly assembly, string @namespace)
/// otherwise, <see langword="false" />.</returns>
public bool Register(TypeRegistration action)
{
this.EnsureNotLocked();
EnsureNotLocked();
ArgumentValidator.EnsureArgumentNotNull(action, "action");
if (actionSet.Contains(action))
return false;
Expand Down Expand Up @@ -143,7 +143,7 @@ private void ProcessPendingActions()
/// <inheritdoc/>
public override void Lock(bool recursive)
{
this.EnsureNotLocked();
EnsureNotLocked();
ProcessPendingActions();
assemblies = new ReadOnlyHashSet<Assembly>((HashSet<Assembly>)assemblies);
base.Lock(recursive);
Expand Down
3 changes: 3 additions & 0 deletions Orm/Xtensive.Orm/Core/Extensions/LockableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// Created by: Alex Yakunin
// Created: 2008.07.04

using System;

namespace Xtensive.Core
{
/// <summary>
Expand All @@ -16,6 +18,7 @@ public static class LockableExtensions
/// </summary>
/// <param name="lockable">Lockable object to check.</param>
/// <exception cref="InstanceIsLockedException">Specified instance is locked.</exception>
[Obsolete("Use LockableBase.EnsureNotLocked method instead.")]
public static void EnsureNotLocked(this ILockable lockable)
{
ArgumentValidator.EnsureArgumentNotNull(lockable, "lockable");
Expand Down
8 changes: 4 additions & 4 deletions Orm/Xtensive.Orm/Core/Interfaces/ILockable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2003-2010 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Copyright (C) 2003-2022 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.

namespace Xtensive.Core
{
Expand All @@ -23,7 +23,7 @@ public interface ILockable
bool IsLocked { get; }

/// <summary>
/// Locks the instance (non-recursively).
/// Locks the instance recursively.
/// </summary>
void Lock();

Expand Down
42 changes: 17 additions & 25 deletions Orm/Xtensive.Orm/Core/LockableBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2003-2010 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Copyright (C) 2003-2022 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alex Yakunin
// Created: 2007.11.22

Expand All @@ -16,36 +16,28 @@ namespace Xtensive.Core
[Serializable]
public abstract class LockableBase: ILockable
{
private bool isLocked;

/// <inheritdoc/>
public bool IsLocked
public bool IsLocked { [DebuggerStepThrough] get; private set; }

/// <summary>
/// Ensures the object is not locked (see <see cref="ILockable.Lock()"/>) yet.
/// </summary>
/// <exception cref="InstanceIsLockedException">The instance is locked.</exception>
public void EnsureNotLocked()
{
[DebuggerStepThrough]
get { return isLocked; }
if (IsLocked) {
throw new InstanceIsLockedException(Strings.ExInstanceIsLocked);
}
}

/// <inheritdoc/>
public void Lock()
{
Lock(true);
}
public void Lock() => Lock(true);

/// <inheritdoc/>
public virtual void Lock(bool recursive)
{
isLocked = true;
}
public virtual void Lock(bool recursive) => IsLocked = true;


/// <summary>
/// Unlocks the object.
/// Sets <see cref="IsLocked"/> to <see langword="false"/>.
/// </summary>
protected void Unlock()
{
isLocked = false;
}


// Constructors

Expand All @@ -63,7 +55,7 @@ protected LockableBase()
/// <param name="isLocked">Initial <see cref="IsLocked"/> property value.</param>
protected LockableBase(bool isLocked)
{
this.isLocked = isLocked;
IsLocked = isLocked;
}
}
}
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm/Modelling/Actions/ActionSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ActionScope LogAction()
public void Add(NodeAction action)
{
ArgumentValidator.EnsureArgumentNotNull(action, "action");
this.EnsureNotLocked();
EnsureNotLocked();
// Only locked actions can be added
var ca = action as PropertyChangeAction;
if (ca!=null && actions.Count!=0) {
Expand All @@ -56,7 +56,7 @@ public void Add(NodeAction action)
actions.RemoveAt(lastIndex);
}
}
action.Lock(true);
action.Lock(true);
actions.Add(action);
}

Expand Down
8 changes: 4 additions & 4 deletions Orm/Xtensive.Orm/Modelling/Actions/CreateNodeAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Type Type {
get { return type; }
set {
ArgumentValidator.EnsureArgumentNotNull(value, "value");
this.EnsureNotLocked();
EnsureNotLocked();
type = value;
}
}
Expand All @@ -44,7 +44,7 @@ public string Name {
get { return name; }
set {
ArgumentValidator.EnsureArgumentNotNullOrEmpty(value, "value");
this.EnsureNotLocked();
EnsureNotLocked();
name = value;
}
}
Expand All @@ -56,7 +56,7 @@ public string Name {
public int? Index {
get { return index; }
set {
this.EnsureNotLocked();
EnsureNotLocked();
index = value;
}
}
Expand All @@ -71,7 +71,7 @@ public object[] Parameters {
return parameters==null ? null : (object[]) parameters.Clone();
}
set {
this.EnsureNotLocked();
EnsureNotLocked();
parameters = value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Orm/Xtensive.Orm/Modelling/Actions/DataAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public DataHint DataHint
get { return dataHint; }
set
{
this.EnsureNotLocked();
EnsureNotLocked();
dataHint = value;
Path = dataHint.SourceTablePath;
}
Expand Down
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm/Modelling/Actions/GroupingNodeAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GroupingNodeAction : NodeAction
public string Comment {
get { return comment; }
set {
this.EnsureNotLocked();
EnsureNotLocked();
comment = value;
}
}
Expand All @@ -46,7 +46,7 @@ public IList<NodeAction> Actions {
public void Add(NodeAction action)
{
ArgumentValidator.EnsureArgumentNotNull(action, "action");
this.EnsureNotLocked();
EnsureNotLocked();
// Only locked actions can be added
var ca = action as PropertyChangeAction;
if (ca!=null && actions.Count!=0) {
Expand Down
8 changes: 4 additions & 4 deletions Orm/Xtensive.Orm/Modelling/Actions/MoveNodeAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class MoveNodeAction : NodeAction
public string Parent {
get { return parent; }
set {
this.EnsureNotLocked();
EnsureNotLocked();
parent = value;
}
}
Expand All @@ -42,7 +42,7 @@ public string Parent {
public string Name {
get { return name; }
set {
this.EnsureNotLocked();
EnsureNotLocked();
name = value;
}
}
Expand All @@ -53,7 +53,7 @@ public string Name {
public int? Index {
get { return index; }
set {
this.EnsureNotLocked();
EnsureNotLocked();
index = value;
}
}
Expand All @@ -65,7 +65,7 @@ public int? Index {
public string NewPath {
get { return newPath; }
set {
this.EnsureNotLocked();
EnsureNotLocked();
newPath = value;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm/Modelling/Actions/NodeAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class NodeAction : LockableBase,
public string Path {
get { return path; }
set {
this.EnsureNotLocked();
EnsureNotLocked();
path = value;
}
}
Expand All @@ -39,7 +39,7 @@ public string Path {
public Difference Difference {
get { return difference; }
set {
this.EnsureNotLocked();
EnsureNotLocked();
difference = value;
}
}
Expand Down
Loading