Exemplo n.º 1
0
        public void Run()
        {
            AEnum a = AEnum.Two;
            BEnum b = (BEnum)a;

            Console.WriteLine(b);
        }
Exemplo n.º 2
0
        public static void Serialize <T>(
            [NotNull] this FileInfo fileInfo,
            [CanBeNull]    T obj,
            DuplicateFileResolution duplicateFileResolution = DuplicateFileResolution.Error,
            JsonSerializerSettings?settings = default
            )
        {
            switch (duplicateFileResolution)
            {
            case DuplicateFileResolution.Error:
                fileInfo.SerializeCautiously(obj, settings);
                break;

            case DuplicateFileResolution.Overwrite:
                fileInfo.SerializeForcefully(obj, settings);
                break;

            case DuplicateFileResolution.Backup:
                fileInfo.SerializeSafely(obj, settings);
                break;

            default:
                throw BEnum.InvalidEnumArgumentException(nameof(duplicateFileResolution), duplicateFileResolution);
            }

            Console.WriteLine($"💾 → {fileInfo.ToUri()}");
        }
Exemplo n.º 3
0
 public static bool Boolean(this Should should)
 {
     return(should switch {
         Should.Pass => true,
         Should.Fail => false,
         _ => throw BEnum.InvalidEnumArgumentException(nameof(should), should)
     });
Exemplo n.º 4
0
        public static TypeNameStyle Reduce(this TypeNameStyle style, int steps = 1)
        {
            var newStep = (int)style - steps;

            newStep = newStep.Clamp(0, BEnum.GetValues <TypeNameStyle>().Cast <int>().Max());
            return((TypeNameStyle)newStep);
        }
Exemplo n.º 5
0
 public static char ToChar(this DirectorySeparator separator)
 {
     return(separator switch {
         DirectorySeparator.Universal => '/',
         DirectorySeparator.Windows => '\\',
         DirectorySeparator.PlatformDependent => Path.DirectorySeparatorChar,
         _ => throw BEnum.InvalidEnumArgumentException(nameof(separator), separator)
     });
Exemplo n.º 6
0
 private static string StylizeGenericTypeArguments([NotNull, ItemCanBeNull] IEnumerable <Type> genericTypeArguments, [CanBeNull] PrettificationSettings settings)
 {
     settings ??= Prettification.DefaultPrettificationSettings;
     return(settings.TypeLabelStyle.Value switch {
         TypeNameStyle.None => "",
         TypeNameStyle.Full => genericTypeArguments.Select(it => it.PrettifyType(settings)).JoinString(", "),
         TypeNameStyle.Short => genericTypeArguments.Select(_ => "").JoinString(","),
         _ => throw BEnum.InvalidEnumArgumentException(nameof(settings.TypeLabelStyle.Value), settings.TypeLabelStyle.Value)
     });
Exemplo n.º 7
0
 private static object GetHeader(
     [NotNull, ItemCanBeNull]
     IEnumerable values,
     [CanBeNull] Type valueType,
     [NotNull]   string fallback,
     [NotNull]   PrettificationSettings settings
     )
 {
     return(settings.HeaderStyle.Value switch {
         HeaderStyle.None => fallback,
         HeaderStyle.TypeNames => valueType ?? InferType(values),
         _ => throw BEnum.InvalidEnumArgumentException(nameof(settings.HeaderStyle), settings.HeaderStyle.Value)
     });
Exemplo n.º 8
0
        public static string PrettifyEnumerable(
            [NotNull][ItemCanBeNull]
            IEnumerable enumerable,
            [NotNull] PrettificationSettings settings
            )
        {
            var asObjects      = enumerable.Cast <object>();
            var enumerableType = enumerable.GetType();
            var lineStyle      = settings?.PreferredLineStyle.Value ?? default;
            var innerSettings  = settings.JsonClone(
                it => {
                it.EnumLabelStyle.Set(TypeNameStyle.None);
                it.TypeLabelStyle.Set(it.TypeLabelStyle.Value.Reduce());
            }
                );

            return(lineStyle switch {
                LineStyle.Dynamic => PrettifyEnumerable_DynamicLine(asObjects, enumerableType, settings, innerSettings),
                LineStyle.Multi => PrettifyEnumerable_MultiLine(asObjects, enumerableType, settings, innerSettings),
                LineStyle.Single => PrettifyEnumerable_SingleLine(asObjects, enumerableType, settings, innerSettings),
                _ => throw BEnum.InvalidEnumArgumentException(nameof(PrettificationSettings.PreferredLineStyle), lineStyle)
            });
Exemplo n.º 9
0
 /// <summary>
 /// The number of <see cref="TimeUnit.Ticks"/> for a <b>single</b> instance of <paramref name="timeUnit"/>.
 /// </summary>
 /// <param name="timeUnit">the original <see cref="TimeUnit"/></param>
 /// <returns>the number of <see cref="TimeUnit.Ticks"/> per <paramref name="timeUnit"/></returns>
 /// <exception cref="System.ComponentModel.InvalidEnumArgumentException">if an unsupported <see cref="TimeUnit"/> is provided</exception>
 public static long TicksPer(this TimeUnit timeUnit)
 {
     return(TicksPerUnit.ContainsKey(timeUnit) ? TicksPerUnit[timeUnit] : throw BEnum.InvalidEnumArgumentException(nameof(timeUnit), timeUnit));
 }
Exemplo n.º 10
0
 public static bool IsBetween(this int value, int min, int max, Clusivity clusivity             = Clusivity.Inclusive) => clusivity == Clusivity.Inclusive ? value >= min && value <= max : clusivity == Clusivity.Exclusive ? value > min && value < max : throw BEnum.InvalidEnumArgumentException(nameof(clusivity), clusivity);
Exemplo n.º 11
0
	public void SayByteEnumArray (BEnum[] data, string str)
	{
		for (int i = 0 ; i != data.Length ; i++)
			Console.WriteLine ("data[" + i + "]: " + data[i]);

		Console.WriteLine (str);
	}