- Timestamp:
- 10/03/18 17:48:20 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceReintegration/HeuristicLab.Persistence/4.0/Core/TypeInfo.cs
r15986 r16210 42 42 constructor = null; 43 43 Type = type; 44 StorableTypeAttribute = StorableTypeAttribute.GetStorableTypeAttribute(type); 44 45 Fields = Enumerable.Empty<ComponentInfo>(); 45 46 Properties = Enumerable.Empty<ComponentInfo>(); … … 56 57 private void Reflect() { 57 58 var type = Type; 58 StorableTypeAttribute = StorableTypeAttribute.GetStorableTypeAttribute(type); 59 59 60 if (StorableTypeAttribute != null) { 60 61 string guidPrefix = StorableTypeAttribute.Guid.ToString().ToUpper(); … … 78 79 79 80 foreach (var field in fieldInfos) { 81 var name = field.Name; 80 82 var attrib = StorableAttribute.GetStorableAttribute(field); 81 var name = attrib == null || string.IsNullOrEmpty(attrib.Name) ? field.Name : attrib.Name; 83 84 if (attrib != null) { 85 if (!string.IsNullOrEmpty(attrib.Name) && !string.IsNullOrEmpty(attrib.OldName)) 86 throw new PersistenceException("Cannot use Name and OldName at the same time."); 87 88 if (!string.IsNullOrEmpty(attrib.Name)) name = attrib.Name; 89 else if (!string.IsNullOrEmpty(attrib.OldName)) name = attrib.OldName; 90 } 91 92 var nameParts = name.Split('.').ToArray(); 93 var sourceType = type; 94 var tmpGuid = Guid.Empty; 95 96 for (int i = 0; i < nameParts.Length; i++) { 97 var part = nameParts[i]; 98 if (part == "base") sourceType = sourceType.BaseType; 99 else if (Guid.TryParse(part, out tmpGuid)) { 100 if (i != 0 || nameParts.Length != 2) throw new PersistenceException("Invalid field path specified."); 101 guidPrefix = tmpGuid.ToString().ToUpper(); 102 break; 103 } else if (i != nameParts.Length - 1) 104 throw new PersistenceException("Invalid field path specified."); 105 else break; 106 } 107 108 if (sourceType != type) { 109 name = nameParts[nameParts.Length - 1]; 110 guidPrefix = StorableTypeAttribute.GetStorableTypeAttribute(sourceType).Guid.ToString().ToUpper(); 111 } else if (tmpGuid != Guid.Empty) { 112 name = nameParts[nameParts.Length - 1]; 113 } 114 82 115 fields.Add(new ComponentInfo(name, guidPrefix + "." + name, field, attrib, true, true)); 83 116 } … … 93 126 94 127 foreach (var property in propertyInfos) { 128 var name = property.Name; 95 129 var attrib = StorableAttribute.GetStorableAttribute(property); 96 if ((!property.CanRead || !property.CanWrite) && (attrib == null || !attrib.AllowOneWay)) 97 throw new PersistenceException("Properties must be readable and writable or have one way serialization explicitly enabled."); 98 99 var name = attrib == null || string.IsNullOrEmpty(attrib.Name) ? property.Name : attrib.Name; 130 131 if (attrib != null) { 132 if (!string.IsNullOrEmpty(attrib.Name) && !string.IsNullOrEmpty(attrib.OldName)) 133 throw new PersistenceException("Cannot use Name and OldName at the same time."); 134 135 if (attrib.AllowOneWay && !string.IsNullOrEmpty(attrib.OldName)) 136 throw new PersistenceException("Cannot use AllowOneWay and OldName at the same time."); 137 138 if (!string.IsNullOrEmpty(attrib.Name)) name = attrib.Name; 139 else if (!string.IsNullOrEmpty(attrib.OldName)) name = attrib.OldName; 140 } 141 142 if ((!property.CanRead || !property.CanWrite) && (attrib == null || !attrib.AllowOneWay && string.IsNullOrEmpty(attrib.OldName))) 143 throw new PersistenceException("Properties must be readable and writable or have one way serialization explicitly enabled or use OldName."); 144 145 var nameParts = name.Split('.').ToArray(); 146 var sourceType = type; 147 var tmpGuid = Guid.Empty; 148 149 for (int i = 0; i < nameParts.Length; i++) { 150 var part = nameParts[i]; 151 if (part == "base") sourceType = sourceType.BaseType; 152 else if (Guid.TryParse(part, out tmpGuid)) { 153 if (i != 0 || nameParts.Length != 2) throw new PersistenceException("Invalid field path specified."); 154 guidPrefix = tmpGuid.ToString().ToUpper(); 155 break; 156 } else if (i != nameParts.Length - 1) 157 throw new PersistenceException("Invalid field path specified."); 158 else break; 159 } 160 161 if (sourceType != type) { 162 name = nameParts[nameParts.Length - 1]; 163 guidPrefix = StorableTypeAttribute.GetStorableTypeAttribute(sourceType).Guid.ToString().ToUpper(); 164 } else if (tmpGuid != Guid.Empty) { 165 name = nameParts[nameParts.Length - 1]; 166 } 167 100 168 properties.Add(new ComponentInfo(name, guidPrefix + "." + name, property, attrib, property.CanRead, property.CanWrite)); 101 169 }
Note: See TracChangeset
for help on using the changeset viewer.