Exemple #1
0
        public uint GetBoxId(object o)
        {
            uint boxId;

            if (o == null)
            {
                boxId = 0;
            }
            else
            {
                if (object2BoxId.TryGetValue(o, out boxId))
                {
                    return(boxId);
                }
                var type     = o.GetType();
                var typeInfo = StaticCache.GetTypeInfo(type);
                if (typeInfo.Transformer == null)
                {
                    throw new ArgumentException("Cannot serialize object of type " + o.GetType());
                }
                boxId = ++BoxCount;
                typeInfo.Used++;
                object2BoxId.Add(o, boxId);
                var box = typeInfo.Transformer.CreateBox(o, this);
                boxId2Box.Add(boxId, box);
                objectsToProcess.Enqueue(Tuple.Create(o, box));
            }
            return(boxId);
        }
Exemple #2
0
 public object CreateInstance(Type type)
 {
     try {
         return(StaticCache.GetTypeInfo(type).GetConstructor()());
     } catch (Exception e) {
         throw new PersistenceException("Deserialization failed.", e);
     }
 }
Exemple #3
0
        private static void ExecuteAfterDeserializationHooks(IEnumerator <object> e)
        {
            var emptyArgs = new object[0];

            while (e.MoveNext())
            {
                var obj = e.Current;

                if (obj == null || !StorableTypeAttribute.IsStorableType(obj.GetType()))
                {
                    continue;
                }

                var typeList = new LinkedList <Type>();
                for (var type = obj.GetType(); type != null; type = type.BaseType)
                {
                    typeList.AddFirst(type);
                }

                foreach (var type in typeList)
                {
                    if (!StorableTypeAttribute.IsStorableType(type))
                    {
                        continue;
                    }

                    var typeInfo = StaticCache.GetTypeInfo(type);
                    foreach (var hook in typeInfo.AfterDeserializationHooks)
                    {
                        try {
                            hook.Invoke(obj, emptyArgs);
                        } catch (TargetInvocationException t) {
                            throw t.InnerException;
                        }
                    }
                }
            }
        }