Last change
on this file since 1688 was
1652,
checked in by epitzer, 16 years ago
|
Implement missing primitive formatter for char and add more comprehensive tests. (#548)
|
File size:
1.3 KB
|
Line | |
---|
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 | if (type == typeof(object)) {
|
---|
20 | return true;
|
---|
21 | }
|
---|
22 | foreach (var attribute in type.GetCustomAttributes(false)) {
|
---|
23 | EmptyStorableClassAttribute empty = attribute as EmptyStorableClassAttribute;
|
---|
24 | if (empty != null) {
|
---|
25 | emptyTypeInfo.Add(type, true);
|
---|
26 | return true;
|
---|
27 | }
|
---|
28 | }
|
---|
29 | int nFields = 0;
|
---|
30 | foreach (MemberInfo memberInfo in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) {
|
---|
31 | if (memberInfo.MemberType == MemberTypes.Field ||
|
---|
32 | memberInfo.MemberType == MemberTypes.Property)
|
---|
33 | nFields += 1;
|
---|
34 | }
|
---|
35 | if (nFields == 0) {
|
---|
36 | emptyTypeInfo.Add(type, true);
|
---|
37 | return true;
|
---|
38 | }
|
---|
39 | emptyTypeInfo.Add(type, false);
|
---|
40 | return false;
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.