- Timestamp:
- 03/16/11 14:47:32 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Persistence/3.3
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/TupleSerializer.cs
r5698 r5712 63 63 public IEnumerable<Tag> CreateMetaInfo(object obj) { 64 64 Type t = obj.GetType(); 65 for (int i = 1; i <=t.GetGenericArguments().Length; i++) {65 for (int i = 1; i <= t.GetGenericArguments().Length; i++) { 66 66 string name = string.Format("Item{0}", i); 67 67 yield return new Tag(name, t.GetProperty(name).GetValue(obj, null)); … … 79 79 static TupleSerializer() { 80 80 foreach (MethodInfo mi in typeof(Tuple).GetMethods(public_static).Where(mi => mi.Name == "Create")) { 81 CreateMethods[mi.GetGenericArguments().Length -1] = mi;81 CreateMethods[mi.GetGenericArguments().Length - 1] = mi; 82 82 } 83 83 } … … 85 85 public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) { 86 86 var values = metaInfo.Select(t => t.Value).ToArray(); 87 MethodInfo createMethod = CreateMethods[values.Length-1].MakeGenericMethod(values.Select(v => v.GetType()).ToArray()); 87 88 MethodInfo createMethod = CreateMethods[values.Length - 1].MakeGenericMethod(type.GetGenericArguments()); 88 89 return createMethod.Invoke(null, values.ToArray()); 89 90 } -
branches/DataAnalysis Refactoring/HeuristicLab.Persistence/3.3/HeuristicLab.Persistence-3.3.csproj
r5290 r5712 142 142 <Compile Include="Default\CompositeSerializers\CompactNumberArray2StringSerializer.cs" /> 143 143 <Compile Include="Default\CompositeSerializers\ConcreteDictionarySerializer.cs" /> 144 <Compile Include="Default\CompositeSerializers\TupleSerializer.cs" /> 144 145 <Compile Include="Default\CompositeSerializers\HashSetSerializer.cs" /> 145 146 <Compile Include="Default\CompositeSerializers\DictionarySerializer.cs" /> -
branches/DataAnalysis Refactoring/HeuristicLab.Persistence/3.3/Tests/UseCases.cs
r5445 r5712 1243 1243 } 1244 1244 1245 [TestMethod] 1246 public void TupleTest() { 1247 var t1 = Tuple.Create(1); 1248 var t2 = Tuple.Create('1', "2"); 1249 var t3 = Tuple.Create(3.0, 3f, 5); 1250 var t4 = Tuple.Create(Tuple.Create(1, 2, 3), Tuple.Create(4, 5, 6), Tuple.Create(8, 9, 10)); 1251 var tuple = Tuple.Create(t1, t2, t3, t4); 1252 XmlGenerator.Serialize(tuple, tempFile); 1253 var newTuple = XmlParser.Deserialize<Tuple<Tuple<int>, Tuple<char, string>, Tuple<double, float, int>, Tuple<Tuple<int, int, int>, Tuple<int, int, int>, Tuple<int, int, int>>>>(tempFile); 1254 Assert.AreEqual(tuple, newTuple); 1255 } 1256 1245 1257 1246 1258
Note: See TracChangeset
for help on using the changeset viewer.