public void Configure(object target, PropertyInfo property, ConfiguratorPropertyAttribute configuratorProperty) { var shouldConfigure = true; if (configuratorProperty is OptionalConfiguratorPropertyAttribute optionalConfiguratorProperty) { shouldConfigure = ConsoleUtils.ReadYesNoKey(optionalConfiguratorProperty.OptionalQuestion); Console.WriteLine(); } if (shouldConfigure) { ConfigureInternal(target, property, configuratorProperty); } }
protected override void ConfigureInternal(object target, PropertyInfo property, ConfiguratorPropertyAttribute configuratorPropertyAttr) { var defaultValue = property.GetValue(target); Console.WriteLine(configuratorPropertyAttr.SetupQuestion); if (defaultValue != null) { Console.WriteLine($"(default={defaultValue})."); } var convertedValue = ConsoleUtils.ReadObject($"Can not be presented as {property.PropertyType.Name}. Please enter value again.", property.PropertyType); property.SetValue(target, convertedValue); }
protected override void ConfigureInternal(object target, PropertyInfo property, ConfiguratorPropertyAttribute configuratorPropertyAttr) { if (!property.PropertyType.IsArray) { throw new GeneratorInvalidOperationException($"Property {property.Name} (type={property.PropertyType.Name}) is not array."); } var defaultValue = property.GetValue(target); Console.WriteLine(configuratorPropertyAttr.SetupQuestion); if (defaultValue != null) { Console.WriteLine($"(default={defaultValue})."); } var values = Console.ReadLine()?.Split(",") ?? Enumerable.Empty <string>(); var itemType = property.PropertyType.GetElementType(); var convertedValues = values.Select(v => Convert.ChangeType(v, itemType)).ToArray(); var convertedArray = Array.CreateInstance(itemType, convertedValues.Length); Array.Copy(convertedValues, convertedArray, convertedValues.Length); property.SetValue(target, convertedArray); }
protected override void ConfigureInternal(object target, PropertyInfo property, ConfiguratorPropertyAttribute configuratorPropertyAttr) { var typeNamingModel = new TypeNamingModel(); foreach (var setupAction in SetupActions) { if (TryReadEntry(setupAction.Key, out var entry)) { setupAction.Value(typeNamingModel, entry); } } property.SetValue(target, typeNamingModel); }
protected abstract void ConfigureInternal( object target, PropertyInfo property, ConfiguratorPropertyAttribute configuratorPropertyAttr);
protected override void ConfigureInternal(object target, PropertyInfo property, ConfiguratorPropertyAttribute configuratorPropertyAttr) { Console.WriteLine($"{configuratorPropertyAttr.SetupQuestion} (y/n)"); Console.Write($"(default={property.GetValue(target)}): "); property.SetValue(target, ConsoleUtils.ReadYesNoKey()); Console.WriteLine(); }