Changeset 3577 for trunk/sources
- Timestamp:
- 05/01/10 12:37:16 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs
r3016 r3577 223 223 compositeSerializer.CreateMetaInfo(value), 224 224 emitTypeInfo); 225 throw CreatePersistenceException(type );225 throw CreatePersistenceException(type, "Could not determine how to serialize a value."); 226 226 } catch (Exception x) { 227 227 if (isTestRun) { 228 228 exceptions.Add(x); 229 229 return new List<ISerializationToken>().GetEnumerator(); 230 } else if (x is PersistenceException) { 231 throw; 230 232 } else { 231 throw ;233 throw CreatePersistenceException(type, "Uncaught exception during serialization: " + x.Message); 232 234 } 233 235 } finally { … … 236 238 } 237 239 238 private PersistenceException CreatePersistenceException(Type type ) {240 private PersistenceException CreatePersistenceException(Type type, string message) { 239 241 StringBuilder sb = new StringBuilder(); 240 sb.Append("Could not determine how to serialize a value of type \"") 242 sb.Append(message) 243 .Append("Type was \"") 241 244 .Append(type.VersionInvariantName()) 242 245 .AppendLine("\"") … … 248 251 .Append(" ---- (") 249 252 .Append(ps.GetType().VersionInvariantName()) 250 .AppendLine(")"); 253 .AppendLine(")"); 251 254 sb.AppendLine("Rejected by all composite serializers:"); 252 255 foreach (var cs in configuration.CompositeSerializers) -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableReflection.cs
r3554 r3577 144 144 145 145 private static StorableClassAttribute GetStorableClassAttribute(Type type) { 146 return (StorableClassAttribute)type 147 .GetCustomAttributes(typeof(StorableClassAttribute), false) 148 .SingleOrDefault(); 146 lock (storableClassCache) { 147 if (storableClassCache.ContainsKey(type)) 148 return storableClassCache[type]; 149 StorableClassAttribute attribute = type 150 .GetCustomAttributes(typeof(StorableClassAttribute), false) 151 .SingleOrDefault() as StorableClassAttribute; 152 storableClassCache.Add(type, attribute); 153 return attribute; 154 } 149 155 } 150 156 151 p rivatestatic bool HasStorableClassAttribute(Type type) {152 return type.GetCustomAttributes(typeof(StorableClassAttribute), false).Length > 0;157 public static bool HasStorableClassAttribute(Type type) { 158 return GetStorableClassAttribute(type) != null; 153 159 } 160 161 private static Dictionary<Type, StorableClassAttribute> storableClassCache = 162 new Dictionary<Type, StorableClassAttribute>(); 154 163 155 164 #endregion -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableSerializer.cs
r3553 r3577 39 39 /// </returns> 40 40 public bool CanSerialize(Type type) { 41 bool markedStorable = StorableReflection.HasStorableClassAttribute(type); 41 42 if (GetConstructor(type) == null) 42 return false; 43 return StorableReflection.IsEmptyOrStorableType(type, true); 43 if (markedStorable) 44 throw new Exception("[Storable] type has no default constructor and no [StorableConstructor]"); 45 else 46 return false; 47 if (!StorableReflection.IsEmptyOrStorableType(type, true)) 48 if (markedStorable) 49 throw new Exception("[Storable] type has non emtpy, non [Storable] base classes"); 50 else 51 return false; 52 return true; 44 53 } 45 54 … … 53 62 /// </returns> 54 63 public string JustifyRejection(Type type) { 64 StringBuilder sb = new StringBuilder(); 55 65 if (GetConstructor(type) == null) 56 return "no default constructor and no storable constructor";66 sb.Append("class has no default constructor and no [StorableConstructor]"); 57 67 if (!StorableReflection.IsEmptyOrStorableType(type, true)) 58 return "class is not marked with the storable class attribute";59 return "no reason";68 sb.Append("class (or one of its bases) is not empty and not marked [Storable]; "); 69 return sb.ToString(); 60 70 } 61 71 … … 154 164 155 165 private Dictionary<HookDesignator, List<StorableReflection.Hook>> hookCache = 156 new Dictionary<HookDesignator, List<StorableReflection.Hook>>(); 166 new Dictionary<HookDesignator, List<StorableReflection.Hook>>(); 157 167 158 168 #endregion
Note: See TracChangeset
for help on using the changeset viewer.