From 0b8b11e78fb123d36dff80940a23af3e4146fd71 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:55:16 -0400 Subject: [PATCH] style(SyncDictionary): code formatting --- Assets/Mirror/Core/SyncDictionary.cs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Assets/Mirror/Core/SyncDictionary.cs b/Assets/Mirror/Core/SyncDictionary.cs index 70ba9fdd4..cbfc670e8 100644 --- a/Assets/Mirror/Core/SyncDictionary.cs +++ b/Assets/Mirror/Core/SyncDictionary.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; @@ -5,13 +6,12 @@ namespace Mirror { public class SyncIDictionary : SyncObject, IDictionary, IReadOnlyDictionary { - public delegate void SyncDictionaryChanged(Operation op, TKey key, TValue item); + public Action Callback; protected readonly IDictionary objects; public int Count => objects.Count; public bool IsReadOnly => !IsWritable(); - public event SyncDictionaryChanged Callback; public enum Operation : byte { @@ -275,21 +275,15 @@ public void Add(TKey key, TValue value) public void Add(KeyValuePair item) => Add(item.Key, item.Value); - public bool Contains(KeyValuePair item) - { - return TryGetValue(item.Key, out TValue val) && EqualityComparer.Default.Equals(val, item.Value); - } + public bool Contains(KeyValuePair item) => TryGetValue(item.Key, out TValue val) && EqualityComparer.Default.Equals(val, item.Value); public void CopyTo(KeyValuePair[] array, int arrayIndex) { if (arrayIndex < 0 || arrayIndex > array.Length) - { throw new System.ArgumentOutOfRangeException(nameof(arrayIndex), "Array Index Out of Range"); - } + if (array.Length - arrayIndex < Count) - { throw new System.ArgumentException("The number of items in the SyncDictionary is greater than the available space from arrayIndex to the end of the destination array"); - } int i = arrayIndex; foreach (KeyValuePair item in objects) @@ -303,9 +297,8 @@ public bool Remove(KeyValuePair item) { bool result = objects.Remove(item.Key); if (result) - { AddOperation(Operation.OP_REMOVE, item.Key, item.Value, true); - } + return result; } @@ -316,9 +309,9 @@ public bool Remove(KeyValuePair item) public class SyncDictionary : SyncIDictionary { - public SyncDictionary() : base(new Dictionary()) {} - public SyncDictionary(IEqualityComparer eq) : base(new Dictionary(eq)) {} - public SyncDictionary(IDictionary d) : base(new Dictionary(d)) {} + public SyncDictionary() : base(new Dictionary()) { } + public SyncDictionary(IEqualityComparer eq) : base(new Dictionary(eq)) { } + public SyncDictionary(IDictionary d) : base(new Dictionary(d)) { } public new Dictionary.ValueCollection Values => ((Dictionary)objects).Values; public new Dictionary.KeyCollection Keys => ((Dictionary)objects).Keys; public new Dictionary.Enumerator GetEnumerator() => ((Dictionary)objects).GetEnumerator();