Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3190 was 3027, checked in by epitzer, 15 years ago

uncomment broken persistence analysis (#548)

File size: 3.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Persistence.Core;
6using System.Windows.Forms;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using System.Reflection;
9
10namespace HeuristicLab.Persistence.GUI {
11  public class PersistenceAnalysis {
12
13    public static bool IsSerializable(Type type, Configuration config) {
14      if (config.PrimitiveSerializers.Any(ps => ps.SourceType == type))
15        return true;
16      foreach (var cs in config.CompositeSerializers) {
17        if (cs.CanSerialize(type))
18          return true;
19      }
20      return false;
21    }
22
23    private static bool DerivesFrom(Type baseType, Type type) {
24      if (type == baseType)
25        return true;
26      if (type.BaseType == null)
27        return false;
28      return DerivesFrom(baseType, type.BaseType);
29    }
30
31    public static IEnumerable<Type> NonSerializableTypes(Configuration config) {
32      var types = new List<Type>();
33      var storableInconsistentcy = new List<Type>();
34      foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
35        if (assembly.FullName.StartsWith("System.") ||
36          assembly.FullName.StartsWith("HeuristicLab.PluginInfrastructure") ||
37          assembly.FullName.StartsWith("log4net") ||
38          assembly.FullName.StartsWith("WindowsBase") ||
39          assembly.FullName.StartsWith("WeifenLuo") ||
40          assembly.FullName.StartsWith("ICSharpCode") ||
41          assembly.FullName.StartsWith("Mono") ||
42          assembly.FullName.StartsWith("Netron"))
43          continue;
44        foreach (var type in assembly.GetTypes()) {         
45          if (type.IsInterface || type.IsAbstract ||
46              type.FullName.StartsWith("System.") ||
47              type.FullName.StartsWith("Microsoft.") ||             
48              type.FullName.Contains("<") ||
49              type.FullName.Contains(">") ||
50              DerivesFrom(typeof(Exception), type) ||
51              DerivesFrom(typeof(Control), type) ||
52              DerivesFrom(typeof(System.EventArgs), type) ||
53              DerivesFrom(typeof(System.Attribute), type) ||
54              type.GetInterface("HeuristicLab.MainForm.IUserInterfaceItem") != null
55            )           
56            continue;
57          try {
58            if (!IsSerializable(type, config))
59              types.Add(type);
60            /* if (!IsCorrectlyStorable(type))
61              storableInconsistentcy.Add(type); */
62          } catch {
63            types.Add(type);
64          }
65        }
66      }
67      return types;
68    }
69
70    /* private static bool IsCorrectlyStorable(Type type) {
71      if (StorableAttribute.GetStorableMembers(type).Count() > 0) {
72        if (!StorableClassAttribute.IsStorableType(type, true))
73          return false;
74        if (type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Type.EmptyTypes, null) == null &&
75          StorableConstructorAttribute.GetStorableConstructor(type) == null)
76          return false;
77      }
78      return true;
79    }  */ 
80  }
81}
Note: See TracBrowser for help on using the repository browser.