Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Persistence.GUI/3.3/PersistenceAnalysis.cs @ 14728

Last change on this file since 14728 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Persistence.Core;
27
28namespace HeuristicLab.Persistence.GUI {
29  public class PersistenceAnalysis {
30
31    public static bool IsSerializable(Type type, Configuration config) {
32      if (config.PrimitiveSerializers.Any(ps => ps.SourceType == type))
33        return true;
34      foreach (var cs in config.CompositeSerializers) {
35        if (cs.CanSerialize(type))
36          return true;
37      }
38      return false;
39    }
40
41    private static bool DerivesFrom(Type baseType, Type type) {
42      if (type == baseType)
43        return true;
44      if (type.BaseType == null)
45        return false;
46      return DerivesFrom(baseType, type.BaseType);
47    }
48
49    public static IEnumerable<Type> NonSerializableTypes(Configuration config) {
50      var types = new List<Type>();
51      var storableInconsistentcy = new List<Type>();
52      foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
53        if (assembly.FullName.StartsWith("System.") ||
54          assembly.FullName.StartsWith("HeuristicLab.PluginInfrastructure") ||
55          assembly.FullName.StartsWith("log4net") ||
56          assembly.FullName.StartsWith("WindowsBase") ||
57          assembly.FullName.StartsWith("WeifenLuo") ||
58          assembly.FullName.StartsWith("ICSharpCode") ||
59          assembly.FullName.StartsWith("Mono") ||
60          assembly.FullName.StartsWith("Netron"))
61          continue;
62        foreach (var type in assembly.GetTypes()) {
63          if (type.IsInterface || type.IsAbstract ||
64              type.FullName.StartsWith("System.") ||
65              type.FullName.StartsWith("Microsoft.") ||
66              type.FullName.Contains("<") ||
67              type.FullName.Contains(">") ||
68              DerivesFrom(typeof(Exception), type) ||
69              DerivesFrom(typeof(Control), type) ||
70              DerivesFrom(typeof(System.EventArgs), type) ||
71              DerivesFrom(typeof(System.Attribute), type) ||
72              type.GetInterface("HeuristicLab.MainForm.IUserInterfaceItem") != null
73            )
74            continue;
75          try {
76            if (!IsSerializable(type, config))
77              types.Add(type);
78            /* if (!IsCorrectlyStorable(type))
79              storableInconsistentcy.Add(type); */
80          }
81          catch {
82            types.Add(type);
83          }
84        }
85      }
86      return types;
87    }
88
89    /* private static bool IsCorrectlyStorable(Type type) {
90      if (StorableAttribute.GetStorableMembers(type).Count() > 0) {
91        if (!StorableClassAttribute.IsStorableType(type, true))
92          return false;
93        if (type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Type.EmptyTypes, null) == null &&
94          StorableConstructorAttribute.GetStorableConstructor(type) == null)
95          return false;
96      }
97      return true;
98    }  */
99  }
100}
Note: See TracBrowser for help on using the repository browser.