/// <summary> /// Podesava vrednosti celog objekta - bez nasledjenih /// </summary> /// <param name="settings">The settings.</param> /// <param name="instanceName">Name of the instance.</param> /// <param name="parentName">Name of the parent.</param> /// <param name="loger">The loger.</param> public static void editSettings(Object settings, String instanceName = "", String parentName = "", ILogBuilder loger = null) { Type settingsType = settings.GetType(); PropertyInfo[] props = settingsType.GetProperties(); List <PropertyInfo> propList = new List <PropertyInfo>(); foreach (PropertyInfo pro in props) { if (pro.CanWrite) { if (pro.PropertyType.IsEnum) { propList.Add(pro); } else if (pro.PropertyType.IsPrimitive) { propList.Add(pro); } else if (pro.PropertyType == typeof(String)) { propList.Add(pro); } else { if (pro.DeclaringType == settingsType) { if (pro.Name != "Item") { propList.Add(pro); } else { } } } } } props = propList.ToArray(); String titleLine = ""; if (String.IsNullOrEmpty(instanceName)) { titleLine = "Variables [" + props.Length + "] in an instance of [" + settingsType.Name + "]."; } else { if (String.IsNullOrEmpty(parentName)) { titleLine = "Variables [" + props.Length + "] in [" + parentName + "->" + instanceName + "] of [" + settingsType.Name + "]."; } else { titleLine = "Variables [" + props.Length + "] in [" + instanceName + "] of [" + settingsType.Name + "]."; } } Console.WriteLine(titleLine); Console.WriteLine(); builderForMarkdown input_builderForMarkdown = (builderForMarkdown)loger; if (input_builderForMarkdown != null) { input_builderForMarkdown.rootTabLevel(); input_builderForMarkdown.AppendHeading(titleLine, 1); input_builderForMarkdown.AppendTableRow(acePaletteVariationRole.header, "Caption", "Property", "Value", "New value", "Description"); } foreach (PropertyInfo prop in props) { List <String> msgOut = new List <string>(); DescriptionAttribute descAttribute; DisplayNameAttribute displayNameAttribute; String description = ""; String displayName = ""; Object[] propAttributes = prop.GetCustomAttributes(false); foreach (Object propAtt in propAttributes) { descAttribute = propAtt as DescriptionAttribute; if (descAttribute != null) { description = descAttribute.Description; } displayNameAttribute = propAtt as DisplayNameAttribute; if (displayNameAttribute != null) { displayName = displayNameAttribute.DisplayName; } } Object propValue = null; propValue = prop.GetValue(settings, null); Object propNewValue = new Object(); Console.WriteLine(); Console.WriteLine("" + displayName + " (" + prop.Name + ") = " + propValue.ToString()); Console.WriteLine("-- " + description); String oldValue = propValue.ToString(); propNewValue = null; if (prop.PropertyType.IsEnum) { propNewValue = askForOption("Select value from list below", propValue); } else { switch (prop.PropertyType.Name.ToLower()) { case "string": propNewValue = askForStringInline("Insert new value", propValue as String); break; case "decimal": String tmpString = askForStringInline("Insert new value", propValue.ToString()); Decimal decimalResult; if (Decimal.TryParse(tmpString, out decimalResult)) { propNewValue = decimalResult; } else { Console.WriteLine("Invalid input - default value set: " + propValue.ToString()); propNewValue = propValue; } break; case "int32": String tmpStringInt = askForStringInline("Insert new value", propValue.ToString()); Int32 intResult; if (Int32.TryParse(tmpStringInt, out intResult)) { propNewValue = intResult; } else { Console.WriteLine("Invalid input - default value set: " + propValue.ToString()); propNewValue = propValue; } break; case "bool": case "boolean": propNewValue = askYesNo("Select new value", (Boolean)propValue); break; } } if (propNewValue != null) { prop.SetValue(settings, propNewValue, new object[0]); Console.WriteLine("Value set: " + propNewValue.ToString()); } else { Console.WriteLine("Skipping parameter: " + prop.Name + ":" + prop.PropertyType.Name); } input_builderForMarkdown.AppendTableRow(acePaletteVariationRole.none, displayName, prop.Name, oldValue, propNewValue.ToString(), description); Console.WriteLine(); } }