private void BuildTypeCache() { externalTypeCache = new List <TypeMapping>(); Dictionary <Assembly, bool> assemblies = new Dictionary <Assembly, bool>(); foreach (var pair in typeCache) { string serializer = null; IPrimitiveSerializer f = configuration.GetPrimitiveSerializer(pair.Key); if (f != null) { serializer = f.GetType().AssemblyQualifiedName; assemblies[f.GetType().Assembly] = true; } else { ICompositeSerializer d = configuration.GetCompositeSerializer(pair.Key); serializer = d.GetType().AssemblyQualifiedName; assemblies[d.GetType().Assembly] = true; } externalTypeCache.Add(new TypeMapping(pair.Value, pair.Key.AssemblyQualifiedName, serializer)); assemblies[pair.Key.Assembly] = true; } Dictionary <string, bool> files = new Dictionary <string, bool>(); foreach (Assembly a in assemblies.Keys) { files[a.CodeBase] = true; } requiredFiles = new List <string>(files.Keys); }
public Midwife(Type type, ICompositeSerializer compositeSerializer, int? id) { this.type = type; this.compositeSerializer = compositeSerializer; this.Id = id; MetaMode = false; metaInfo = new List<Tag>(); customValues = new List<Tag>(); }
public Midwife(Type type, ICompositeSerializer compositeSerializer, int?id) { this.type = type; this.compositeSerializer = compositeSerializer; this.Id = id; MetaMode = false; metaInfo = new List <Tag>(); customValues = new List <Tag>(); }
private IEnumerator <ISerializationToken> Serialize(DataMemberAccessor accessor, object obj) { object value = accessor.Get(obj); if (value == null) { return(NullReferenceEnumerator(accessor.Name)); } Type type = value.GetType(); if (obj2id.ContainsKey(value)) { return(ReferenceEnumerator(accessor.Name, obj2id[value])); } bool emitTypeInfo = false; if (!typeCache.ContainsKey(type)) { typeCache.Add(type, typeCache.Count); emitTypeInfo = InterleaveTypeInformation; } int typeId = typeCache[type]; int?id = null; if (!type.IsValueType) { id = obj2id.Count; obj2id.Add(value, (int)id); } try { objectGraphTrace.Push(accessor.Name); IPrimitiveSerializer primitiveSerializer = configuration.GetPrimitiveSerializer(type); if (primitiveSerializer != null) { return(PrimitiveEnumerator( accessor.Name, typeId, primitiveSerializer.Format(value), id, emitTypeInfo)); } ICompositeSerializer compositeSerializer = configuration.GetCompositeSerializer(type); if (compositeSerializer != null) { return(CompositeEnumerator( accessor.Name, compositeSerializer.Decompose(value), id, typeId, compositeSerializer.CreateMetaInfo(value), emitTypeInfo)); } throw CreatePersistenceException(type, "Could not determine how to serialize a value.", true); } catch (Exception x) { if (isTestRun) { exceptions.Add(x); return(new List <ISerializationToken>().GetEnumerator()); } else if (x is PersistenceException) { throw; } else { throw CreatePersistenceException( type, string.Format("Uncaught exception during serialization:{0}{1}", Environment.NewLine, x), false); } } finally { objectGraphTrace.Pop(); } }