Rev | Line | |
---|
[1623] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Reflection;
|
---|
| 4 |
|
---|
| 5 | namespace HeuristicLab.Persistence.Default.Decomposers.Storable {
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | [AttributeUsage(
|
---|
| 9 | AttributeTargets.Class,
|
---|
| 10 | AllowMultiple = false,
|
---|
| 11 | Inherited = false)]
|
---|
| 12 | public class EmptyStorableClassAttribute : Attribute {
|
---|
| 13 |
|
---|
| 14 | private static readonly Dictionary<Type, bool> emptyTypeInfo = new Dictionary<Type, bool>();
|
---|
| 15 |
|
---|
| 16 | public static bool IsEmptyStorable(Type type) {
|
---|
| 17 | if (emptyTypeInfo.ContainsKey(type))
|
---|
| 18 | return emptyTypeInfo[type];
|
---|
| 19 | foreach (var attribute in type.GetCustomAttributes(false)) {
|
---|
| 20 | EmptyStorableClassAttribute empty = attribute as EmptyStorableClassAttribute;
|
---|
| 21 | if (empty != null) {
|
---|
| 22 | emptyTypeInfo.Add(type, true);
|
---|
| 23 | return true;
|
---|
| 24 | }
|
---|
| 25 | }
|
---|
| 26 | int nFields = 0;
|
---|
| 27 | foreach (MemberInfo memberInfo in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) {
|
---|
| 28 | if (memberInfo.MemberType == MemberTypes.Field ||
|
---|
| 29 | memberInfo.MemberType == MemberTypes.Property)
|
---|
| 30 | nFields += 1;
|
---|
| 31 | }
|
---|
| 32 | if (nFields == 0) {
|
---|
| 33 | emptyTypeInfo.Add(type, true);
|
---|
| 34 | return true;
|
---|
| 35 | }
|
---|
| 36 | emptyTypeInfo.Add(type, false);
|
---|
| 37 | return false;
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.