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

Commit 77dc497

Browse files
I thought this would work
1 parent 84b7e17 commit 77dc497

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public LocalConfigBranchDictionary(IDictionary<string, ConfigBranch> dictionary)
197197
}
198198

199199
[Serializable]
200-
class RemoteConfigBranchDictionary : SerializableDictionary<string, SerializableDictionary<string, ConfigBranch>>, IRemoteConfigBranchDictionary
200+
class RemoteConfigBranchDictionary : SerializableNestedDictionary<string, ConfigBranch>, IRemoteConfigBranchDictionary
201201
{
202202
public RemoteConfigBranchDictionary()
203203
{ }
@@ -206,7 +206,7 @@ public RemoteConfigBranchDictionary(IDictionary<string, IDictionary<string, Conf
206206
{
207207
foreach (var pair in dictionary)
208208
{
209-
this.Add(pair.Key, new LocalConfigBranchDictionary(pair.Value));
209+
Add(pair.Key, pair.Value.ToDictionary(valuePair => valuePair.Key, valuePair => valuePair.Value));
210210
}
211211
}
212212

@@ -262,7 +262,7 @@ bool IDictionary<string, IDictionary<string, ConfigBranch>>.TryGetValue(string k
262262
{
263263
value = null;
264264

265-
SerializableDictionary<string, ConfigBranch> branches;
265+
Dictionary<string, ConfigBranch> branches;
266266
if (TryGetValue(key, out branches))
267267
{
268268
value = branches;
@@ -610,13 +610,21 @@ public void RemoveRemoteBranch(string remote, string branch)
610610

611611
public void SetRemotes(IDictionary<string, ConfigRemote> remoteDictionary, IDictionary<string, IDictionary<string, ConfigBranch>> branchDictionary)
612612
{
613+
var now = DateTimeOffset.Now;
613614
configRemotes = new ConfigRemoteDictionary(remoteDictionary);
614615
remoteConfigBranches = new RemoteConfigBranchDictionary(branchDictionary);
616+
Logger.Trace("SetRemotes {0}", now);
617+
Logger.Trace("remoteDictionary.Length: {0}", remoteDictionary.Count);
618+
Logger.Trace("branchDictionary.Length: {0}", branchDictionary.Count);
619+
SaveData(now, true);
615620
}
616621

617622
public void SetLocals(IDictionary<string, ConfigBranch> branchDictionary)
618623
{
624+
var now = DateTimeOffset.Now;
619625
localConfigBranches = new LocalConfigBranchDictionary(branchDictionary);
626+
Logger.Trace("SetRemotes {0}", now);
627+
SaveData(now, true);
620628
}
621629

622630
public override string LastUpdatedAtString

src/UnityExtension/Assets/Editor/GitHub.Unity/SerializableDictionary.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,56 @@ public void OnAfterDeserialize()
4040
this.Add(keys[i], values[i]);
4141
}
4242
}
43+
44+
[Serializable]
45+
public class ArrayContainer<T>
46+
{
47+
[SerializeField]
48+
public T[] Values = new T[0];
49+
}
50+
51+
[Serializable]
52+
public class SerializableNestedDictionary<TKey, TValue> : Dictionary<TKey, Dictionary<TKey, TValue>>, ISerializationCallbackReceiver
53+
{
54+
[SerializeField] private TKey[] keys = new TKey[0];
55+
[SerializeField] private ArrayContainer<TKey>[] subKeys = new ArrayContainer<TKey>[0];
56+
[SerializeField] private ArrayContainer<TValue>[] subKeyValues = new ArrayContainer<TValue>[0];
57+
58+
// save the dictionary to lists
59+
public void OnBeforeSerialize()
60+
{
61+
var keyList = new List<TKey>();
62+
var subKeysList = new List<ArrayContainer<TKey>>();
63+
var subKeysValuesList = new List<ArrayContainer<TValue>>();
64+
65+
foreach (var pair in this)
66+
{
67+
var pairKey = pair.Key;
68+
keyList.Add(pairKey);
69+
70+
var serializeSubKeys = new List<TKey>();
71+
var serializeSubKeyValues = new List<TValue>();
72+
73+
var subDictionary = pair.Value;
74+
foreach (var subPair in subDictionary)
75+
{
76+
serializeSubKeys.Add(subPair.Key);
77+
serializeSubKeyValues.Add(subPair.Value);
78+
}
79+
80+
subKeysList.Add(new ArrayContainer<TKey> { Values = serializeSubKeys.ToArray() });
81+
subKeysValuesList.Add(new ArrayContainer<TValue> { Values = serializeSubKeyValues.ToArray() });
82+
}
83+
84+
keys = keyList.ToArray();
85+
subKeys = subKeysList.ToArray();
86+
subKeyValues = subKeysValuesList.ToArray();
87+
}
88+
89+
// load dictionary from lists
90+
public void OnAfterDeserialize()
91+
{
92+
this.Clear();
93+
}
94+
}
4395
}

0 commit comments

Comments
 (0)