Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3816 was 3742, checked in by gkronber, 15 years ago

Fixed GPL license headers and deleted files which are not referenced by projects. #893

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Text;
26using HeuristicLab.Persistence.Core;
27using System.Windows.Forms;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using System.Reflection;
30
31namespace HeuristicLab.Persistence.GUI {
32  public class PersistenceAnalysis {
33
34    public static bool IsSerializable(Type type, Configuration config) {
35      if (config.PrimitiveSerializers.Any(ps => ps.SourceType == type))
36        return true;
37      foreach (var cs in config.CompositeSerializers) {
38        if (cs.CanSerialize(type))
39          return true;
40      }
41      return false;
42    }
43
44    private static bool DerivesFrom(Type baseType, Type type) {
45      if (type == baseType)
46        return true;
47      if (type.BaseType == null)
48        return false;
49      return DerivesFrom(baseType, type.BaseType);
50    }
51
52    public static IEnumerable<Type> NonSerializableTypes(Configuration config) {
53      var types = new List<Type>();
54      var storableInconsistentcy = new List<Type>();
55      foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
56        if (assembly.FullName.StartsWith("System.") ||
57          assembly.FullName.StartsWith("HeuristicLab.PluginInfrastructure") ||
58          assembly.FullName.StartsWith("log4net") ||
59          assembly.FullName.StartsWith("WindowsBase") ||
60          assembly.FullName.StartsWith("WeifenLuo") ||
61          assembly.FullName.StartsWith("ICSharpCode") ||
62          assembly.FullName.StartsWith("Mono") ||
63          assembly.FullName.StartsWith("Netron"))
64          continue;
65        foreach (var type in assembly.GetTypes()) {         
66          if (type.IsInterface || type.IsAbstract ||
67              type.FullName.StartsWith("System.") ||
68              type.FullName.StartsWith("Microsoft.") ||             
69              type.FullName.Contains("<") ||
70              type.FullName.Contains(">") ||
71              DerivesFrom(typeof(Exception), type) ||
72              DerivesFrom(typeof(Control), type) ||
73              DerivesFrom(typeof(System.EventArgs), type) ||
74              DerivesFrom(typeof(System.Attribute), type) ||
75              type.GetInterface("HeuristicLab.MainForm.IUserInterfaceItem") != null
76            )           
77            continue;
78          try {
79            if (!IsSerializable(type, config))
80              types.Add(type);
81            /* if (!IsCorrectlyStorable(type))
82              storableInconsistentcy.Add(type); */
83          } catch {
84            types.Add(type);
85          }
86        }
87      }
88      return types;
89    }
90
91    /* private static bool IsCorrectlyStorable(Type type) {
92      if (StorableAttribute.GetStorableMembers(type).Count() > 0) {
93        if (!StorableClassAttribute.IsStorableType(type, true))
94          return false;
95        if (type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Type.EmptyTypes, null) == null &&
96          StorableConstructorAttribute.GetStorableConstructor(type) == null)
97          return false;
98      }
99      return true;
100    }  */ 
101  }
102}
Note: See TracBrowser for help on using the repository browser.