fix: reformat using C# rules

This commit is contained in:
ZavaruKitsu
2022-10-08 19:26:34 +03:00
parent a731e2a8d0
commit 5ab15621a0
180 changed files with 13136 additions and 13081 deletions
+9 -10
View File
@@ -1,15 +1,14 @@
using System;
namespace TelegramBotBase.Tools
namespace TelegramBotBase.Tools;
public static class Arrays
{
public static class Arrays
public static T[] Shift<T>(T[] array, int positions)
{
public static T[] Shift<T>(T[] array, int positions)
{
var copy = new T[array.Length];
Array.Copy(array, 0, copy, array.Length - positions, positions);
Array.Copy(array, positions, copy, 0, array.Length - positions);
return copy;
}
var copy = new T[array.Length];
Array.Copy(array, 0, copy, array.Length - positions, positions);
Array.Copy(array, positions, copy, 0, array.Length - positions);
return copy;
}
}
}
+57 -58
View File
@@ -2,64 +2,63 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace TelegramBotBase.Tools
namespace TelegramBotBase.Tools;
public static class Console
{
public static class Console
private static EventHandler __handler;
private static readonly List<Action> __actions = new();
static Console()
{
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);
private delegate bool EventHandler(CtrlType sig);
private static EventHandler __handler;
private static List<Action> __actions = new List<Action>();
private enum CtrlType
{
CtrlCEvent = 0,
CtrlBreakEvent = 1,
CtrlCloseEvent = 2,
CtrlLogoffEvent = 5,
CtrlShutdownEvent = 6
}
static Console()
{
}
public static void SetHandler(Action action)
{
__actions.Add(action);
if (__handler != null)
return;
__handler += Handler;
SetConsoleCtrlHandler(__handler, true);
}
private static bool Handler(CtrlType sig)
{
switch (sig)
{
case CtrlType.CtrlCEvent:
case CtrlType.CtrlLogoffEvent:
case CtrlType.CtrlShutdownEvent:
case CtrlType.CtrlCloseEvent:
foreach (var a in __actions)
{
a();
}
return false;
default:
return false;
}
}
}
}
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);
public static void SetHandler(Action action)
{
__actions.Add(action);
if (__handler != null)
{
return;
}
__handler += Handler;
SetConsoleCtrlHandler(__handler, true);
}
private static bool Handler(CtrlType sig)
{
switch (sig)
{
case CtrlType.CtrlCEvent:
case CtrlType.CtrlLogoffEvent:
case CtrlType.CtrlShutdownEvent:
case CtrlType.CtrlCloseEvent:
foreach (var a in __actions)
{
a();
}
return false;
default:
return false;
}
}
private delegate bool EventHandler(CtrlType sig);
private enum CtrlType
{
CtrlCEvent = 0,
CtrlBreakEvent = 1,
CtrlCloseEvent = 2,
CtrlLogoffEvent = 5,
CtrlShutdownEvent = 6
}
}
+19 -22
View File
@@ -2,34 +2,31 @@
using System.Reflection;
using TelegramBotBase.Form;
namespace TelegramBotBase.Tools
namespace TelegramBotBase.Tools;
public static class Conversion
{
public static class Conversion
public static void CustomConversionChecks(FormBase form, KeyValuePair<string, object> p, PropertyInfo f)
{
public static void CustomConversionChecks(FormBase form, KeyValuePair<string, object> p, PropertyInfo f)
//Newtonsoft Int64/Int32 converter issue
if (f.PropertyType == typeof(int))
{
//Newtonsoft Int64/Int32 converter issue
if (f.PropertyType == typeof(int))
if (int.TryParse(p.Value.ToString(), out var i))
{
if (int.TryParse(p.Value.ToString(), out var i))
{
f.SetValue(form, i);
}
return;
f.SetValue(form, i);
}
//Newtonsoft Double/Decimal converter issue
if (f.PropertyType == typeof(decimal) | f.PropertyType == typeof(decimal?))
{
decimal d = 0;
if (decimal.TryParse(p.Value.ToString(), out d))
{
f.SetValue(form, d);
}
}
return;
}
//Newtonsoft Double/Decimal converter issue
if ((f.PropertyType == typeof(decimal)) | (f.PropertyType == typeof(decimal?)))
{
decimal d = 0;
if (decimal.TryParse(p.Value.ToString(), out d))
{
f.SetValue(form, d);
}
}
}
}
}
+43 -42
View File
@@ -1,47 +1,48 @@
using System;
namespace TelegramBotBase.Tools
namespace TelegramBotBase.Tools;
public static class Time
{
public static class Time
public static bool TryParseDay(string src, DateTime currentDate, out int resultDay)
{
public static bool TryParseDay(string src, DateTime currentDate, out int resultDay)
{
return int.TryParse(src, out resultDay) && resultDay >= 1 && resultDay <= DateTime.DaysInMonth(currentDate.Year, currentDate.Month);
}
public static bool TryParseMonth(string src, out int resultMonth)
{
return int.TryParse(src, out resultMonth) && resultMonth >= 1 && resultMonth <= 12;
}
public static bool TryParseYear(string src, out int resultYear)
{
return int.TryParse(src, out resultYear) && resultYear >= 0 && resultYear <= DateTime.MaxValue.Year;
}
public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
{
var diff = dt.DayOfWeek - startOfWeek;
if (diff < 0)
{
diff += 7;
}
return dt.AddDays(-1 * diff).Date;
}
public static DateTime EndOfWeek(this DateTime dt, DayOfWeek startOfWeek)
{
return StartOfWeek(dt, startOfWeek).AddDays(6);
}
public static DateTime FirstDayOfMonth(this DateTime date)
{
return new DateTime(date.Year, date.Month, 1);
}
public static DateTime LastDayOfMonth(this DateTime date)
{
return FirstDayOfMonth(date).AddMonths(1).AddDays(-1);
}
return int.TryParse(src, out resultDay) && resultDay >= 1 &&
resultDay <= DateTime.DaysInMonth(currentDate.Year, currentDate.Month);
}
}
public static bool TryParseMonth(string src, out int resultMonth)
{
return int.TryParse(src, out resultMonth) && resultMonth >= 1 && resultMonth <= 12;
}
public static bool TryParseYear(string src, out int resultYear)
{
return int.TryParse(src, out resultYear) && resultYear >= 0 && resultYear <= DateTime.MaxValue.Year;
}
public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
{
var diff = dt.DayOfWeek - startOfWeek;
if (diff < 0)
{
diff += 7;
}
return dt.AddDays(-1 * diff).Date;
}
public static DateTime EndOfWeek(this DateTime dt, DayOfWeek startOfWeek)
{
return StartOfWeek(dt, startOfWeek).AddDays(6);
}
public static DateTime FirstDayOfMonth(this DateTime date)
{
return new DateTime(date.Year, date.Month, 1);
}
public static DateTime LastDayOfMonth(this DateTime date)
{
return FirstDayOfMonth(date).AddMonths(1).AddDays(-1);
}
}