2
2
3
3
namespace JasperFx . Core . Descriptions ;
4
4
5
+ /// <summary>
6
+ /// Just gives an object more control over how it creates an OptionsDescription
7
+ /// </summary>
8
+ public interface IDescribeMyself
9
+ {
10
+ OptionsDescription ToDescription ( ) ;
11
+ }
12
+
13
+ public class OptionSet
14
+ {
15
+ public string Subject { get ; set ; }
16
+ public string [ ] SummaryColumns { get ; set ; } = Array . Empty < string > ( ) ;
17
+ public List < OptionsDescription > Rows { get ; set ; } = new ( ) ;
18
+ }
19
+
5
20
/// <summary>
6
21
/// Just a serializable, readonly view of system configuration to be used for diagnostic purposes
7
22
/// </summary>
@@ -11,6 +26,11 @@ public class OptionsDescription
11
26
public List < OptionsValue > Properties { get ; set ; } = new ( ) ;
12
27
13
28
public Dictionary < string , OptionsDescription > Children = new ( ) ;
29
+
30
+ /// <summary>
31
+ /// Children "sets" of option descriptions
32
+ /// </summary>
33
+ public Dictionary < string , OptionSet > Sets = new ( ) ;
14
34
15
35
// For serialization
16
36
public OptionsDescription ( )
@@ -25,14 +45,17 @@ public OptionsDescription(object subject)
25
45
}
26
46
27
47
var type = subject . GetType ( ) ;
48
+
49
+ Subject = type . FullNameInCode ( ) ;
50
+
28
51
foreach ( var property in type . GetProperties ( ) . Where ( x => ! x . HasAttribute < IgnoreDescriptionAttribute > ( ) ) )
29
52
{
30
53
if ( property . HasAttribute < ChildDescriptionAttribute > ( ) )
31
54
{
32
55
var child = property . GetValue ( subject ) ;
33
56
if ( child == null ) continue ;
34
57
35
- var childDescription = new OptionsDescription ( child ) ;
58
+ var childDescription = child is IDescribeMyself describes ? describes . ToDescription ( ) : new OptionsDescription ( child ) ;
36
59
Children [ property . Name ] = childDescription ;
37
60
38
61
continue ;
@@ -42,4 +65,50 @@ public OptionsDescription(object subject)
42
65
Properties . Add ( OptionsValue . Read ( property , subject ) ) ;
43
66
}
44
67
}
68
+
69
+ public OptionSet AddChildSet ( string name )
70
+ {
71
+ var subject = $ "{ Subject } .{ name } ";
72
+ var set = new OptionSet { Subject = subject } ;
73
+ Sets [ name ] = set ;
74
+ return set ;
75
+ }
76
+
77
+ public OptionSet AddChildSet ( string name , IEnumerable < object > children )
78
+ {
79
+ var set = AddChildSet ( name ) ;
80
+ foreach ( var child in children )
81
+ {
82
+ var description = child is IDescribeMyself describes
83
+ ? describes . ToDescription ( )
84
+ : new OptionsDescription ( child ) ;
85
+
86
+ set . Rows . Add ( description ) ;
87
+ }
88
+
89
+ return set ;
90
+ }
91
+
92
+ public OptionsValue AddValue ( string name , object value )
93
+ {
94
+ var subject = $ "{ Subject } .{ name } ";
95
+ var optionsValue = new OptionsValue ( subject , name , value ) ;
96
+ Properties . Add ( optionsValue ) ;
97
+
98
+ return optionsValue ;
99
+ }
100
+
101
+ /// <summary>
102
+ /// Case insensitive search for the first property that matches this name
103
+ /// </summary>
104
+ /// <param name="name"></param>
105
+ /// <returns></returns>
106
+ public OptionsValue ? PropertyFor ( string name )
107
+ {
108
+ return Properties . FirstOrDefault ( x => x . Name . EqualsIgnoreCase ( name ) ) ;
109
+ }
110
+
111
+ public Dictionary < string , string > Tags = new ( ) ;
112
+
113
+ public List < MetricDescription > Metrics { get ; set ; } = new ( ) ;
45
114
}
0 commit comments