public void GetOrAddTypeKeyFromCache_New()
        {
            SaveInheritanceAttribute attribute = typeof(KeyBase).GetCustomAttribute <SaveInheritanceAttribute>();

            string key = KeyInheritanceHandler.GetOrAddTypeKeyFromCache(typeof(KeyBase), typeof(KeySubFirst), attribute);

            Assert.AreEqual("First", key);

            Assert.AreEqual(1, attribute.KeySerializeCache.Count);
            Assert.AreEqual(1, attribute.KeyDeserializeCache.Count);

            Assert.AreEqual("First", attribute.KeySerializeCache[typeof(KeySubFirst)]);
            Assert.AreEqual(typeof(KeySubFirst), attribute.KeyDeserializeCache["First"]);
        }
        public void GetOrAddTypeKeyFromCache_Exists()
        {
            SaveInheritanceAttribute attribute = typeof(KeyBase).GetCustomAttribute <SaveInheritanceAttribute>();

            // Fill the cache up.
            var oldSerializeCache   = attribute.KeySerializeCache = new Dictionary <Type, string>();
            var oldDeserializeCache = attribute.KeyDeserializeCache = new Dictionary <string, Type>();

            oldSerializeCache.Add(typeof(KeySubFirst), "First");
            oldDeserializeCache.Add("First", typeof(KeySubFirst));

            string key = KeyInheritanceHandler.GetOrAddTypeKeyFromCache(typeof(KeyBase), typeof(KeySubFirst), attribute);

            Assert.AreEqual("First", key);

            // Ensure it didn't add to the cache.
            Assert.AreEqual(oldSerializeCache, attribute.KeySerializeCache);
            Assert.AreEqual(oldDeserializeCache, attribute.KeyDeserializeCache);

            Assert.AreEqual(1, attribute.KeySerializeCache.Count);
            Assert.AreEqual(1, attribute.KeyDeserializeCache.Count);
        }
Exemple #3
0
        void WriteKeyInheritance(SaveInheritanceAttribute info, Type baseType, Type actualType, ref BitTarget header)
        {
            string key = KeyInheritanceHandler.GetOrAddTypeKeyFromCache(baseType, actualType, info);

            WriteString(key, ref header);
        }