Changeset 16210 for branches/PersistenceReintegration/HeuristicLab.Persistence/4.0/Core/StorableTypeAttribute.cs
- Timestamp:
- 10/03/18 17:48:20 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceReintegration/HeuristicLab.Persistence/4.0/Core/StorableTypeAttribute.cs
r15986 r16210 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 24 25 namespace HeuristicLab.Persistence { 25 26 26 /// <summary> 27 27 /// Mark a class to be considered by the <c>StorableSerializer</c>. 28 28 /// </summary> 29 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)] 29 [AttributeUsage( 30 AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Delegate, 31 Inherited = false, 32 AllowMultiple = false 33 )] 30 34 public sealed class StorableTypeAttribute : Attribute { 35 private static IDictionary<Type, StorableTypeAttribute> attributeCache = new Dictionary<Type, StorableTypeAttribute>(); 31 36 32 37 #region Properties 33 38 /// <summary> 34 39 /// Specify how members are selected for serialization. … … 36 41 public StorableMemberSelection MemberSelection { get; private set; } 37 42 43 /// <summary> 44 /// The GUID that identifies the type. 45 /// </summary> 46 /// <value>The GUID.</value> 38 47 public Guid Guid { get; private set; } 48 #endregion 39 49 40 50 /// <summary> … … 64 74 /// <returns></returns> 65 75 public static bool IsStorableType(Type type) { 66 object[] attribs = type.GetCustomAttributes(typeof(StorableTypeAttribute), false); 67 return attribs.Length > 0; 76 return GetStorableTypeAttribute(type) != null; 68 77 } 69 78 70 79 public static StorableTypeAttribute GetStorableTypeAttribute(Type type) { 71 return (StorableTypeAttribute)Attribute.GetCustomAttribute(type, typeof(StorableTypeAttribute), false); 80 StorableTypeAttribute attrib; 81 82 if (!attributeCache.TryGetValue(type, out attrib)) { 83 attrib = (StorableTypeAttribute)GetCustomAttribute(type, typeof(StorableTypeAttribute), false); 84 if (attrib != null) attributeCache[type] = attrib; 85 } 86 87 return attrib; 72 88 } 73 74 89 } 75 90 }
Note: See TracChangeset
for help on using the changeset viewer.