Changeset 1404
- Timestamp:
- 03/24/09 16:57:25 (16 years ago)
- Location:
- branches/New Persistence Exploration/Persistence/Persistence/Core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/Persistence/Core/Serializer.cs
r1362 r1404 132 132 } 133 133 } 134 if (nSubComponents == 0 ) {134 if (nSubComponents == 0 && ! EmptyStorableClassAttribute.IsEmpyStorable(value)) { 135 135 throw new ApplicationException( 136 136 String.Format( 137 "CustomComposite value of type \"{0}\" contains no subcomponents", 137 "Value of type \"{0}\" has no formatter or decomposer, " + 138 "contains no storable subcomponents, " + 139 "and is not marked as empty storable class.", 138 140 value.GetType().FullName)); 139 141 } -
branches/New Persistence Exploration/Persistence/Persistence/Core/StorableAttribute.cs
r1360 r1404 4 4 5 5 namespace HeuristicLab.Persistence.Core { 6 7 8 [AttributeUsage( 9 AttributeTargets.Class, 10 AllowMultiple=false, 11 Inherited=false)] 12 public class EmptyStorableClassAttribute : Attribute { 13 private static readonly Dictionary<Type, bool> emptyTypeInfo = new Dictionary<Type, bool>(); 14 public static bool IsEmpyStorable(object o) { 15 Type type = o.GetType(); 16 if (emptyTypeInfo.ContainsKey(type)) 17 return emptyTypeInfo[type]; 18 foreach (var attribute in o.GetType().GetCustomAttributes(false)) { 19 EmptyStorableClassAttribute empty = attribute as EmptyStorableClassAttribute; 20 if (empty != null) { 21 emptyTypeInfo.Add(type, true); 22 return true; 23 } 24 } 25 int nFields = 0; 26 foreach ( MemberInfo memberInfo in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ) { 27 if (memberInfo.MemberType == MemberTypes.Field || 28 memberInfo.MemberType == MemberTypes.Property) 29 nFields += 1; 30 } 31 if (nFields == 0) { 32 emptyTypeInfo.Add(type, true); 33 return true; 34 } 35 emptyTypeInfo.Add(type, false); 36 return false; 37 } 38 } 6 39 7 40 [AttributeUsage(
Note: See TracChangeset
for help on using the changeset viewer.