static void Set(SeqCliConfig config, string key, string value) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } var steps = key.Split('.'); if (steps.Length != 2) { throw new ArgumentException("The format of the key is incorrect; run the command without any arguments to view all keys."); } var first = config.GetType().GetTypeInfo().DeclaredProperties .Where(p => p.CanRead && p.GetMethod.IsPublic && !p.GetMethod.IsStatic) .SingleOrDefault(p => Camelize(p.Name) == steps[0]); if (first == null) { throw new ArgumentException("The key could not be found; run the command without any arguments to view all keys."); } var v = first.GetValue(config); if (v is Dictionary <string, SeqCliConnectionConfig> ) { throw new NotSupportedException("Use `seqcli profile create` to configure connection profiles."); } var second = v.GetType().GetTypeInfo().DeclaredProperties .Where(p => p.CanRead && p.GetMethod.IsPublic && !p.GetMethod.IsStatic) .SingleOrDefault(p => Camelize(p.Name) == steps[1]); if (second == null) { throw new ArgumentException("The key could not be found; run the command without any arguments to view all keys."); } if (!second.SetMethod.IsPublic) { throw new ArgumentException("The value is not writeable."); } var targetValue = Convert.ChangeType(value, second.PropertyType); second.SetValue(v, targetValue); }
static void Set(SeqCliConfig config, string key, string value) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } var steps = key.Split('.'); if (steps.Length != 2) { throw new ArgumentException("The format of the key is incorrect; run the command without any arguments to view all keys."); } var first = config.GetType().GetTypeInfo().DeclaredProperties .Where(p => p.GetMethod.IsPublic && !p.GetMethod.IsStatic) .SingleOrDefault(p => Camelize(p.Name) == steps[0]); if (first == null) { throw new ArgumentException("The key could not be found; run the command without any arguments to view all keys."); } var v = first.GetValue(config); var second = v.GetType().GetTypeInfo().DeclaredProperties .Where(p => p.GetMethod.IsPublic && p.SetMethod.IsPublic && !p.GetMethod.IsStatic) .SingleOrDefault(p => Camelize(p.Name) == steps[1]); if (second == null) { throw new ArgumentException("The key could not be found; run the command without any arguments to view all keys."); } var targetValue = Convert.ChangeType(value, second.PropertyType); second.SetValue(v, targetValue); }