Changeset 6224 for branches/PersistenceSpeedUp
- Timestamp:
- 05/17/11 15:10:19 (14 years ago)
- Location:
- branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableClassAnalyzer.cs
r6222 r6224 119 119 return; 120 120 var attribute = (StorableAttribute)fieldInfo.GetCustomAttributes(typeof(StorableAttribute), false).SingleOrDefault(); 121 if (attribute != null && classAttribute.Type != StorableClassType.AllProperties || 122 classAttribute.Type == StorableClassType.AllFields || 123 classAttribute.Type == StorableClassType.AllFieldsAndAllProperties) 121 if (attribute != null) 124 122 typeDescriptor.Fields.Add(new FieldDescriptor(typeDescriptor, fieldInfo, attribute)); 125 123 } … … 131 129 } 132 130 var attribute = (StorableAttribute)propertyInfo.GetCustomAttributes(typeof(StorableAttribute), false).SingleOrDefault(); 133 if (attribute != null && classAttribute.Type != StorableClassType.AllFields || 134 classAttribute.Type == StorableClassType.AllProperties || 135 classAttribute.Type == StorableClassType.AllFieldsAndAllProperties) { 136 if (!(attribute != null && attribute.AllowOneWay || 137 propertyInfo.CanRead && propertyInfo.CanWrite)) 131 if (attribute != null) { 132 if (!(attribute.AllowOneWay || propertyInfo.CanRead && propertyInfo.CanWrite)) 138 133 throw new PersistenceException("Properties have to be read/write or marked as one way storable"); 139 134 typeDescriptor.Properties.Add(new PropertyDescriptor(typeDescriptor, propertyInfo, attribute)); -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableClassAttribute.cs
r5445 r6224 30 30 public sealed class StorableClassAttribute : Attribute { 31 31 32 33 /// <summary>34 /// Specify how members are selected for serialization.35 /// </summary>36 public StorableClassType Type { get; private set; }37 38 /// <summary>39 /// Mark a class to be serialize by the <c>StorableSerizlier</c>40 /// </summary>41 /// <param name="type">The storable class type.</param>42 public StorableClassAttribute(StorableClassType type) {43 Type = type;44 }45 46 32 /// <summary> 47 33 /// Initializes a new instance of the <see cref="StorableClassAttribute"/> class. … … 51 37 public StorableClassAttribute() { } 52 38 53 /// <summary>54 /// Checks if the <see cref="StorableClassAttribute"/> is present on a type.55 /// </summary>56 /// <param name="type">The type which should be checked for the <see cref="StorableClassAttribute"/></param>57 /// <returns></returns>58 public static bool IsStorableClass(Type type) {59 object[] attribs = type.GetCustomAttributes(typeof(StorableClassAttribute), false);60 return attribs.Length > 0;61 }62 63 39 } 64 40 } -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/HeuristicLab.Persistence-3.3.csproj
r6214 r6224 154 154 <Compile Include="Default\CompositeSerializers\NumberEnumerable2StringSerializer.cs" /> 155 155 <Compile Include="Default\CompositeSerializers\StackSerializer.cs" /> 156 <Compile Include="Default\CompositeSerializers\Storable\StorableClassType.cs" />157 156 <Compile Include="Default\CompositeSerializers\Storable\StorableClassAttribute.cs" /> 158 157 <Compile Include="Default\CompositeSerializers\Storable\StorableAttribute.cs" /> -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Tests/UseCases.cs
r6210 r6224 921 921 } 922 922 923 [StorableClass(StorableClassType.AllFields)] 924 public class AllFieldsStorable { 925 public int Value1 = 1; 926 [Storable] 927 public int Value2 = 2; 928 public int Value3 { get; private set; } 929 public int Value4 { get; private set; } 930 [StorableConstructor] 931 public AllFieldsStorable(bool isDeserializing) { 932 if (!isDeserializing) { 933 Value1 = 12; 934 Value2 = 23; 935 Value3 = 34; 936 Value4 = 56; 937 } 938 } 939 } 940 941 [TestMethod] 942 public void TestStorableClassDiscoveryAllFields() { 943 AllFieldsStorable afs = new AllFieldsStorable(false); 944 XmlGenerator.Serialize(afs, tempFile); 945 AllFieldsStorable newAfs = (AllFieldsStorable)XmlParser.Deserialize(tempFile); 946 Assert.AreEqual(afs.Value1, newAfs.Value1); 947 Assert.AreEqual(afs.Value2, newAfs.Value2); 948 Assert.AreEqual(0, newAfs.Value3); 949 Assert.AreEqual(0, newAfs.Value4); 950 } 951 952 [StorableClass(StorableClassType.AllProperties)] 953 public class AllPropertiesStorable { 954 public int Value1 = 1; 955 [Storable] 956 public int Value2 = 2; 957 public int Value3 { get; private set; } 958 public int Value4 { get; private set; } 959 [StorableConstructor] 960 public AllPropertiesStorable(bool isDeserializing) { 961 if (!isDeserializing) { 962 Value1 = 12; 963 Value2 = 23; 964 Value3 = 34; 965 Value4 = 56; 966 } 967 } 968 } 969 970 [TestMethod] 971 public void TestStorableClassDiscoveryAllProperties() { 972 AllPropertiesStorable afs = new AllPropertiesStorable(false); 973 XmlGenerator.Serialize(afs, tempFile); 974 AllPropertiesStorable newAfs = (AllPropertiesStorable)XmlParser.Deserialize(tempFile); 975 Assert.AreEqual(1, newAfs.Value1); 976 Assert.AreEqual(2, newAfs.Value2); 977 Assert.AreEqual(afs.Value3, newAfs.Value3); 978 Assert.AreEqual(afs.Value4, newAfs.Value4); 979 980 } 981 982 [StorableClass(StorableClassType.AllFieldsAndAllProperties)] 983 public class AllFieldsAndAllPropertiesStorable { 984 public int Value1 = 1; 985 [Storable] 986 public int Value2 = 2; 987 public int Value3 { get; private set; } 988 public int Value4 { get; private set; } 989 [StorableConstructor] 990 public AllFieldsAndAllPropertiesStorable(bool isDeserializing) { 991 if (!isDeserializing) { 992 Value1 = 12; 993 Value2 = 23; 994 Value3 = 34; 995 Value4 = 56; 996 } 997 } 998 } 999 1000 [TestMethod] 1001 public void TestStorableClassDiscoveryAllFieldsAndAllProperties() { 1002 AllFieldsAndAllPropertiesStorable afs = new AllFieldsAndAllPropertiesStorable(false); 1003 XmlGenerator.Serialize(afs, tempFile); 1004 AllFieldsAndAllPropertiesStorable newAfs = (AllFieldsAndAllPropertiesStorable)XmlParser.Deserialize(tempFile); 1005 Assert.AreEqual(afs.Value1, newAfs.Value1); 1006 Assert.AreEqual(afs.Value2, newAfs.Value2); 1007 Assert.AreEqual(afs.Value3, newAfs.Value3); 1008 Assert.AreEqual(afs.Value4, newAfs.Value4); 1009 } 1010 1011 [StorableClass(StorableClassType.MarkedOnly)] 923 924 [StorableClass] 1012 925 public class MarkedOnlyStorable { 1013 926 public int Value1 = 1;
Note: See TracChangeset
for help on using the changeset viewer.