public static PrettificationSettings GetEmpty([CanBeNull] Action <PrettificationSettings> modifications = default) { var settings = new PrettificationSettings(); modifications?.Invoke(settings); return(settings); }
internal static Optional <IPrettifier> FindPrettifier( IPrettifierDatabase prettifierDatabase, [NotNull] Type type, [CanBeNull] PrettificationSettings settings, [NotNull, ItemNotNull, InstantHandle] IEnumerable <OptionalPrettifierFinder> finders ) { settings = Prettification.ResolveSettings(settings); settings.TraceWriter.Verbose(() => $"🔎 Attempting to find an {nameof(IPrettifier)} for the type {type.Name}"); var simplified = PrettificationTypeSimplifier.SimplifyType(type, settings); var prettifier = Optional.Optional.FirstWithValue <OptionalPrettifierFinder, IPrettifier>( finders, prettifierDatabase, simplified, settings ); settings.TraceWriter.Info( () => prettifier.IfPresentOrElse( it => $"⛳ Found: {it}", () => "🐸 No prettifier found!" ), 2 ); return(prettifier); }
private static Type SimplifyTypeSwitch([NotNull] Type type, [NotNull] PrettificationSettings settings, int recurCount = 0) { if (SimplestTypes.ContainsKey(type)) { var simplest = SimplestTypes[type]; settings.TraceWriter.Verbose(() => $"🦠 Could not simplify {type.Name} past {simplest.Name}!", recurCount + 2); } var simplified = type switch { { IsEnum : true } => typeof(Enum),
public string PrettifySafely(object cinderella, PrettificationSettings settings = default) { settings ??= Prettification.DefaultPrettificationSettings; settings.TraceWriter.Verbose(() => $"🦺 SAFELY prettifying [{cinderella?.GetType().Name}]"); try { return(Prettify(cinderella, settings)); } catch (Exception e) { var str = $"🧨 Error during prettification of [{cinderella?.GetType().Name}]{cinderella}:\n{e})"; Console.WriteLine(str); return(Prettification.LastResortPrettifier(cinderella, settings)); } }
public string Prettify(object cinderella, PrettificationSettings settings = default) { settings ??= Prettification.DefaultPrettificationSettings; settings.TraceWriter.Verbose(() => $"⚠ DANGEROUSLY prettifying [{cinderella?.GetType().Name}]"); if (cinderella == null) { return(settings.NullPlaceholder); } else if (PrettifierType.IsGenericTypeOrDefinition()) { return(PrettifyGeneric(cinderella, settings)); } else { return(Prettify(TrySlipper(cinderella), settings)); } }
internal static Optional <IPrettifier> FindMatchingGenericPrettifier(IPrettifierDatabase prettifierDatabase, [NotNull] Type type, [NotNull] PrettificationSettings settings) { IPrettifier found = type.IsGenericType ? prettifierDatabase.Find(it => GenericTypesMatch(it.PrettifierType, type)) : default; return(Optional.Optional.OfNullable(found)); }
private static Optional <IPrettifier> FindExactGenericPrettifier(IPrettifierDatabase prettifierDatabase, [NotNull] Type type, [NotNull] PrettificationSettings settings) { return(type.IsGenericType == false ? default : FindExactPrettifier(prettifierDatabase, type.GetGenericTypeDefinition(), settings)); }
internal static Optional <IPrettifier> FindGenericallyTypedPrettifier(IPrettifierDatabase prettifierDatabase, [NotNull] Type type, [NotNull] PrettificationSettings settings) { settings.TraceWriter.Verbose(() => $"-> {nameof(FindGenericallyTypedPrettifier)}({type.Name})", 1); return(Optional.Optional.FirstWithValue <OptionalPrettifierFinder, IPrettifier>( new OptionalPrettifierFinder[] { FindExactGenericPrettifier, FindMatchingGenericPrettifier }, prettifierDatabase, type, settings )); }
internal static Optional <IPrettifier> FindToStringOverridePrettifier([CanBeNull] IPrettifierDatabase prettifierDatabase, [NotNull] Type type, [NotNull] PrettificationSettings settings) { settings.TraceWriter.Verbose(() => $"-> {nameof(FindToStringOverridePrettifier)}({type.Name})", 1); settings.TraceWriter.Warning(() => $"{nameof(FindToStringOverridePrettifier)} is currently DISABLED!"); return(default);
internal static Optional <IPrettifier> FindExactPrettifier([NotNull] IPrettifierDatabase prettifierDatabase, [NotNull] Type type, [NotNull] PrettificationSettings settings) { settings.TraceWriter.Verbose(() => $"-> {nameof(FindExactPrettifier)}({type.Name})", 1); return(Optional.Optional.OfNullable(prettifierDatabase.Find(type))); }
internal static string PrettifyPrettifiable([NotNull] IPrettifiable prettifiable, [NotNull] PrettificationSettings settings) => prettifiable.Prettify(settings);
internal static string PrettifyToString([NotNull] object obj, [NotNull] PrettificationSettings settings) => obj.ToString();
public string PrettifySafely(T cinderella, PrettificationSettings settings = default) { return(PrettifySafely((object)cinderella, settings)); }
public string Prettify(T cinderella, PrettificationSettings settings = default) { return(PrettificationFunction.Invoke(cinderella, settings)); }