Beispiel #1
0
        public static PrettificationSettings GetEmpty([CanBeNull] Action <PrettificationSettings> modifications = default)
        {
            var settings = new PrettificationSettings();

            modifications?.Invoke(settings);
            return(settings);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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),
Beispiel #4
0
        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));
            }
        }
Beispiel #5
0
        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));
            }
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
 private static Optional <IPrettifier> FindExactGenericPrettifier(IPrettifierDatabase prettifierDatabase, [NotNull] Type type, [NotNull] PrettificationSettings settings)
 {
     return(type.IsGenericType == false ? default : FindExactPrettifier(prettifierDatabase, type.GetGenericTypeDefinition(), settings));
 }
Beispiel #8
0
        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
                       ));
        }
Beispiel #9
0
 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);
Beispiel #10
0
 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)));
 }
Beispiel #11
0
 internal static string PrettifyPrettifiable([NotNull] IPrettifiable prettifiable, [NotNull] PrettificationSettings settings) => prettifiable.Prettify(settings);
Beispiel #12
0
 internal static string PrettifyToString([NotNull]     object obj, [NotNull] PrettificationSettings settings) => obj.ToString();
Beispiel #13
0
 public string PrettifySafely(T cinderella, PrettificationSettings settings = default)
 {
     return(PrettifySafely((object)cinderella, settings));
 }
Beispiel #14
0
 public string Prettify(T cinderella, PrettificationSettings settings = default)
 {
     return(PrettificationFunction.Invoke(cinderella, settings));
 }