[3742] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3742] | 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 |
|
---|
| 22 | using System;
|
---|
[3003] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
[4068] | 25 | using System.Windows.Forms;
|
---|
[3003] | 26 | using HeuristicLab.Persistence.Core;
|
---|
| 27 |
|
---|
| 28 | namespace 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;
|
---|
[4068] | 62 | foreach (var type in assembly.GetTypes()) {
|
---|
[3003] | 63 | if (type.IsInterface || type.IsAbstract ||
|
---|
| 64 | type.FullName.StartsWith("System.") ||
|
---|
[4068] | 65 | type.FullName.StartsWith("Microsoft.") ||
|
---|
[3003] | 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
|
---|
[4068] | 73 | )
|
---|
[3003] | 74 | continue;
|
---|
| 75 | try {
|
---|
| 76 | if (!IsSerializable(type, config))
|
---|
| 77 | types.Add(type);
|
---|
[16565] | 78 | } catch {
|
---|
[3003] | 79 | types.Add(type);
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | return types;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 | }
|
---|