/// <summary> /// Returns a deserializer based on a string type. /// </summary> /// <param name="strType">Type of the object for deserialization</param> /// <returns>deserializer based on a string type</returns> public AbstractDeserializer GetDeserializer(string strType) { if (strType == null || strType.Equals("")) { return(null); } AbstractDeserializer abstractDeserializer = null; abstractDeserializer = (AbstractDeserializer)m_htTypeMap[strType]; if (abstractDeserializer != null) { return(abstractDeserializer); } if (strType.StartsWith("[")) { AbstractDeserializer subABSTRACTDeserializer = GetDeserializer(strType.Substring(1)); abstractDeserializer = new CArrayDeserializer(subABSTRACTDeserializer); return(abstractDeserializer); } else { #if COMPACT_FRAMEWORK // do CF stuff if (m_assamblyFiles == null) { m_assamblyFiles = AllAssamblyNamesInCurrentDirectory(); } foreach (string ass in m_assamblyFiles) { string typeString = strType + "," + ass; Type searchType = Type.GetType(typeString); if (searchType != null) { abstractDeserializer = GetDeserializer(searchType); return(abstractDeserializer); } } #else // do other stuff try { //Diese Typsuche funzt bei Mobileloesung nicht: //Es wurde ein andere Suche implementiert Assembly[] ass = AppDomain.CurrentDomain.GetAssemblies(); Type t = null; foreach (Assembly a in ass) { t = a.GetType(strType); if (t != null) { break; } } if (t != null) { abstractDeserializer = GetDeserializer(t); } } catch (Exception) { } #endif } /* TODO: Implementieren Type.GetType(type) geht nicht, man muss die Assembly eingeben. */ //deserializer = getDeserializer(Type.GetType(type)); return(abstractDeserializer); }
/// <summary> /// Returns according deserializer to the given type /// </summary> /// <param name="type">Type of the deserializer</param> /// <returns>Deserializer instance</returns> public AbstractDeserializer GetDeserializer(Type type) { AbstractDeserializer abstractDeserializer = (AbstractDeserializer)m_htDeserializerMap[type]; if (abstractDeserializer == null) { if (typeof(IDictionary).IsAssignableFrom(type)) { abstractDeserializer = new CMapDeserializer(type); } else if (type.IsGenericType && typeof(System.Nullable <>).IsAssignableFrom(type.GetGenericTypeDefinition())) { // nullbarer Typ Type[] args = type.GetGenericArguments(); return(GetDeserializer(args[0])); } else if (type.IsArray) { abstractDeserializer = new CArrayDeserializer(GetDeserializer(type.GetElementType())); } else if (type.IsEnum) { abstractDeserializer = new CEnumDeserializer(type); } else if (typeof(IList).IsAssignableFrom(type) || (type.IsGenericType && typeof(System.Collections.Generic.IEnumerable <>).IsAssignableFrom(type.GetGenericTypeDefinition()))) { abstractDeserializer = new CEnumerableDeserializer(type); } else if (typeof(Exception).IsAssignableFrom(type)) { abstractDeserializer = new CExceptionDeserializer(type); } else if (typeof(ISerializable).IsAssignableFrom(type)) { abstractDeserializer = new CISerializableDeserializer(type); } else { if (m_htCachedDeserializerMap[type.FullName] != null) { abstractDeserializer = (AbstractDeserializer)m_htCachedDeserializerMap[type.FullName]; } else { //加锁防止多线程同时添加同一类型 lock (deserializerLock) { //可能有一个线程已经添加,这里再判断一次 abstractDeserializer = (AbstractDeserializer)m_htCachedDeserializerMap[type.FullName]; if (abstractDeserializer != null) { return(abstractDeserializer); } else { abstractDeserializer = new CObjectDeserializer(type); m_htCachedDeserializerMap.Add(type.FullName, abstractDeserializer); } } } } } return(abstractDeserializer); }