/// <summary> /// Gets the serializer-Instance according to given type /// </summary> /// <param name="type">Type of the objects, that have to be serialized</param> /// <returns>Serializer - Instance</returns> public AbstractSerializer GetSerializer(Type type) { object val; if (type == typeof(decimal?) || type == typeof(decimal)) { int a = 10; } AbstractSerializer abstractSerializer = null; if (!m_htSerializerMap.TryGetValue(type, out val)) { // TODO: Serialisieren von Nullbaren Typen und generischen // Listen if (typeof(IDictionary).IsAssignableFrom(type)) { abstractSerializer = new CMapSerializer(); } else if (type.IsArray) { abstractSerializer = new CArraySerializer(); } else if (typeof(IList).IsAssignableFrom(type)) { abstractSerializer = new CCollectionSerializer(); } else if (typeof(Stream).IsAssignableFrom(type)) { abstractSerializer = new CInputStreamSerializer(); } else if (typeof(Exception).IsAssignableFrom(type)) { abstractSerializer = new CExceptionSerializer(); } else if (type.IsEnum) { abstractSerializer = new CEnumSerializer(); } else { if (m_htCachedSerializerMap.TryGetValue(type.FullName, out val)) { abstractSerializer = (AbstractSerializer)val; } else { abstractSerializer = new CObjectSerializer(type); m_htCachedSerializerMap.Add(type.FullName, abstractSerializer); } } } else { abstractSerializer = (AbstractSerializer)val; } return(abstractSerializer); }
/// <summary> /// Writes any object to the output stream. /// </summary> /// <param name="obj">object to write</param> public override void WriteObject(object obj) { if (obj == null) { WriteNull(); return; } AbstractSerializer abstractSerializer = m_serializerFactory.GetSerializer(obj.GetType()); abstractSerializer.WriteObject(obj, this); }