private static GroupViewModel CreateGroupFromClass(GroupViewModel parent, Type classType, Func<ComfoBoxClient> clientFunc) { var group = new GroupViewModel(classType.Name); parent.Add(group); foreach (var subType in classType.GetNestedTypes()) { CreateGroupFromClass(group, subType, clientFunc); } var instance = classType.CreateInstance(); foreach (var propertyInfo in classType.Properties(Flags.Default)) { var propertyValue = instance.GetPropertyValue(propertyInfo.Name) as IItemValue; if (propertyValue != null && propertyValue.IsReadOnly) { group.Add(new ReadOnlyItemViewModel(propertyInfo.Name, clientFunc) {Item = propertyValue}); } else if (propertyValue is AnalogValue || propertyValue is AnalogValue) { group.Add(new AnalogValueItemViewModel(propertyInfo.Name, clientFunc) {Item = propertyValue}); } else if (propertyValue is DateValue) { group.Add(new ReadOnlyItemViewModel(propertyInfo.Name, clientFunc) {Item = propertyValue}); } else { var enumItem = propertyValue as IEnumValue; group.Add(new EnumItemViewModel(propertyInfo.Name, clientFunc) {Item = propertyValue}); } } return group; }
public static IEnumerable<GroupViewModel> CreateGroups(Func<ComfoBoxClient> clientFunc) { var root = new GroupViewModel("ComfoBox"); CreateGroupFromClass(root, typeof(Zone), clientFunc); CreateGroupFromClass(root, typeof(Tests), clientFunc); CreateGroupFromClass(root, typeof (Warmwater), clientFunc); CreateGroupFromClass(root, typeof (States), clientFunc); CreateGroupFromClass(root, typeof (Time), clientFunc); CreateGroupFromClass(root, typeof (Config), clientFunc); return new[] {root}; }
public void Add(GroupViewModel @group) { Children.Add(group); }