internal static string PrintSettings(int indentLevel = 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < indentLevel; ++i) { sb.Append("\t"); } string indent = sb.ToString(); sb.Clear(); var properties = typeof(Settings).GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var property in properties) { object current = property.GetValue(Current); if (property.PropertyType.GetInterfaces().Contains(typeof(ISettingValue))) { sb.Append($"{indent}{property.Name}: {current}\n"); } else { if (property.PropertyType.GetInterfaces().Contains(typeof(ICollection))) { continue; } if (property.PropertyType == typeof(ProxyConfigAdapter)) { ProxyConfigAdapter proxy = (ProxyConfigAdapter)current; sb.Append($"{indent}{property.Name}: {proxy.ToString(true)}\n"); } } } return(sb.ToString()); }
private void ButtonPrintSettings_OnClick(object sender, RoutedEventArgs e) { Debug.WriteLine("\n======= DebugView ======="); Debug.WriteLine("SETTINGS [Current | (Preview) | Default]"); Debug.WriteLine(""); var properties = typeof(Settings).GetProperties(BindingFlags.Public | BindingFlags.Instance); if (this.PreviewSettings != null) { foreach (var property in properties) { dynamic current = property.GetValue(Settings.Current); dynamic preview = property.GetValue(this.PreviewSettings); dynamic @default = property.GetValue(Settings.Default); if (property.PropertyType.GetInterfaces().Contains(typeof(ISettingValue))) { Debug.WriteLine($"{property.Name,-36}: {current?.ToString(),-25} | {preview?.ToString(),-25} | {@default?.ToString(),-25}"); } else { if (property.PropertyType.GetInterfaces().Contains(typeof(ICollection))) { continue; } if (property.PropertyType == typeof(ProxyConfigAdapter)) { ProxyConfigAdapter cp = (ProxyConfigAdapter)current; ProxyConfigAdapter pp = (ProxyConfigAdapter)preview; ProxyConfigAdapter dp = (ProxyConfigAdapter)@default; Debug.WriteLine($"{property.Name,-36}: {cp?.ToString(true),-30} | {pp?.ToString(true),-30} | {dp?.ToString(true),-30}"); } else if (property.PropertyType.IsPrimitive) { Debug.WriteLine($"{property.Name,-36}: {current?.ToString(),-30} | {preview?.ToString(),-30} | {@default?.ToString(),-30}"); } } } } else { foreach (var property in properties) { dynamic current = property.GetValue(Settings.Current); dynamic @default = property.GetValue(Settings.Default); if (property.PropertyType.GetInterfaces().Contains(typeof(ISettingValue))) { Debug.WriteLine($"{property.Name,-36}: {current?.ToString(),-25} | {@default?.ToString(),-25}"); } else { if (property.PropertyType.GetInterfaces().Contains(typeof(ICollection))) { continue; } if (property.PropertyType == typeof(ProxyConfigAdapter)) { ProxyConfigAdapter cp = (ProxyConfigAdapter)current; ProxyConfigAdapter dp = (ProxyConfigAdapter)@default; Debug.WriteLine($"{property.Name,-36}: {cp?.ToString(true),-30} | {dp?.ToString(true),-30}"); } else if (property.PropertyType.IsPrimitive) { Debug.WriteLine($"{property.Name,-36}: {current?.ToString(),-30} | {@default?.ToString(),-30}"); } } } } Debug.WriteLine("=========================\n"); }