Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 08705a7

Browse files
committed
Format SerializableDictionary according to our coding style
1 parent f15a295 commit 08705a7

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using UnityEngine;
54

6-
75
namespace GitHub.Unity
86
{
97
//http://answers.unity3d.com/answers/809221/view.html
108

119
[Serializable]
1210
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver
1311
{
14-
[SerializeField]
15-
private List<TKey> keys = new List<TKey>();
16-
17-
[SerializeField]
18-
private List<TValue> values = new List<TValue>();
12+
[SerializeField] private List<TKey> keys = new List<TKey>();
13+
[SerializeField] private List<TValue> values = new List<TValue>();
1914

2015
// save the dictionary to lists
2116
public void OnBeforeSerialize()
2217
{
2318
keys.Clear();
2419
values.Clear();
25-
foreach (KeyValuePair<TKey, TValue> pair in this)
20+
foreach (var pair in this)
2621
{
2722
keys.Add(pair.Key);
2823
values.Add(pair.Value);
@@ -32,13 +27,19 @@ public void OnBeforeSerialize()
3227
// load dictionary from lists
3328
public void OnAfterDeserialize()
3429
{
35-
this.Clear();
30+
Clear();
3631

3732
if (keys.Count != values.Count)
38-
throw new Exception(string.Format("there are {0} keys and {1} values after deserialization. Make sure that both key and value types are serializable.", keys.Count, values.Count));
33+
{
34+
throw new Exception(
35+
string.Format("there are {0} keys and {1} values after deserialization. Make sure that both key and value types are serializable.",
36+
keys.Count, values.Count));
37+
}
3938

40-
for (int i = 0; i < keys.Count; i++)
41-
this.Add(keys[i], values[i]);
39+
for (var i = 0; i < keys.Count; i++)
40+
{
41+
Add(keys[i], values[i]);
42+
}
4243
}
4344
}
44-
}
45+
}

0 commit comments

Comments
 (0)