20211113 C#10 Update
This commit is contained in:
parent
438c123876
commit
869dc25fb4
@ -1,10 +1,10 @@
|
|||||||
namespace anbs_cp
|
namespace anbs_cp;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Форматирует число элементов в понятную строку
|
||||||
|
/// </summary>
|
||||||
|
public class CountFormatter: IValueFormatter
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Форматирует число элементов в понятную строку
|
|
||||||
/// </summary>
|
|
||||||
public class CountFormatter : IValueFormatter
|
|
||||||
{
|
|
||||||
#region Cвойства класса
|
#region Cвойства класса
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Имена чисел (тысяч, миллионов, миллиардов и т.п.)
|
/// Имена чисел (тысяч, миллионов, миллиардов и т.п.)
|
||||||
@ -30,5 +30,4 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long[] MaxSizes { get => Delimeters; set => Delimeters = value; }
|
public long[] MaxSizes { get => Delimeters; set => Delimeters = value; }
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
namespace anbs_cp
|
namespace anbs_cp;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Форматирует размер файла/папки в понятную строку
|
||||||
|
/// </summary>
|
||||||
|
public class FileSizeFormatter: IValueFormatter
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Форматирует размер файла/папки в понятную строку
|
|
||||||
/// </summary>
|
|
||||||
public class FileSizeFormatter : IValueFormatter
|
|
||||||
{
|
|
||||||
#region Cвойства класса
|
#region Cвойства класса
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Имена размеров (байт, килобайт, мегабайт, гигабайт и террабайт)
|
/// Имена размеров (байт, килобайт, мегабайт, гигабайт и террабайт)
|
||||||
@ -52,5 +52,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
namespace anbs_cp
|
namespace anbs_cp;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Форматирует размерности в понятную строку
|
||||||
|
/// </summary>
|
||||||
|
public interface IValueFormatter
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Форматирует размерности в понятную строку
|
|
||||||
/// </summary>
|
|
||||||
public interface IValueFormatter
|
|
||||||
{
|
|
||||||
|
|
||||||
#region Определения интерфейса
|
#region Определения интерфейса
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -27,7 +27,7 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">Размерность, требующая форматирования</param>
|
/// <param name="value">Размерность, требующая форматирования</param>
|
||||||
/// <returns>Форматированная размерность (например, 20 Мб)</returns>
|
/// <returns>Форматированная размерность (например, 20 Мб)</returns>
|
||||||
public string Format(long value)
|
public string Format (long value)
|
||||||
{
|
{
|
||||||
//Левая граница
|
//Левая граница
|
||||||
long leftnum;
|
long leftnum;
|
||||||
@ -36,15 +36,9 @@
|
|||||||
|
|
||||||
for (int i = 0; i <= MaxSizes.Length; i++)
|
for (int i = 0; i <= MaxSizes.Length; i++)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
leftnum = i == 0 ? 0 : MaxSizes[i - 1];
|
||||||
leftnum = 0;
|
|
||||||
else
|
|
||||||
leftnum = MaxSizes[i - 1];
|
|
||||||
|
|
||||||
if (i == MaxSizes.Length)
|
rightnum = i == MaxSizes.Length ? long.MaxValue : MaxSizes[i];
|
||||||
rightnum = long.MaxValue;
|
|
||||||
else
|
|
||||||
rightnum = MaxSizes[i];
|
|
||||||
|
|
||||||
if ((value >= leftnum) && (value < rightnum))
|
if ((value >= leftnum) && (value < rightnum))
|
||||||
return $"{FormatValue(value, leftnum)} {ValueNames[i]}";
|
return $"{FormatValue(value, leftnum)} {ValueNames[i]}";
|
||||||
@ -59,7 +53,7 @@
|
|||||||
/// <param name="dividend">Делимое число</param>
|
/// <param name="dividend">Делимое число</param>
|
||||||
/// <param name="divider">Число-делитель</param>
|
/// <param name="divider">Число-делитель</param>
|
||||||
/// <returns>Частное (с DecimalPlaces знаками после запятой)</returns>
|
/// <returns>Частное (с DecimalPlaces знаками после запятой)</returns>
|
||||||
private string FormatValue(long dividend, long divider)
|
private string FormatValue (long dividend, long divider)
|
||||||
{
|
{
|
||||||
if (divider == 0)
|
if (divider == 0)
|
||||||
{
|
{
|
||||||
@ -78,5 +72,4 @@
|
|||||||
return $"{value}";
|
return $"{value}";
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,17 +1,16 @@
|
|||||||
using System.Collections.Generic;
|
namespace anbs_cp;
|
||||||
namespace anbs_cp
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, добавляющий реализацию некоторых методов Delphi, которые упрощают работу в C#.
|
||||||
|
/// </summary>
|
||||||
|
public static class LikeDelphi
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Класс, добавляющий реализацию некоторых методов Delphi, которые упрощают работу в C#.
|
|
||||||
/// </summary>
|
|
||||||
public static class LikeDelphi
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Аналог функции IncludeTrailingBackslash
|
/// Аналог функции IncludeTrailingBackslash
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">Путь, к которому нужно добавить slash</param>
|
/// <param name="path">Путь, к которому нужно добавить slash</param>
|
||||||
/// <returns>Путь со slash в конце</returns>
|
/// <returns>Путь со slash в конце</returns>
|
||||||
public static string IncludeTrailingBackslash(string path)
|
public static string IncludeTrailingBackslash (string path)
|
||||||
{
|
{
|
||||||
string result = path;
|
string result = path;
|
||||||
int Index = path.Length - 1;
|
int Index = path.Length - 1;
|
||||||
@ -27,7 +26,7 @@ namespace anbs_cp
|
|||||||
/// <param name="astring">Строка, которую нужно разбить</param>
|
/// <param name="astring">Строка, которую нужно разбить</param>
|
||||||
/// <param name="delim">Символ-делитель строки</param>
|
/// <param name="delim">Символ-делитель строки</param>
|
||||||
/// <returns>Массив строк</returns>
|
/// <returns>Массив строк</returns>
|
||||||
public static List<string> ParseString(string astring, char delim)
|
public static List<string> ParseString (string astring, char delim)
|
||||||
{
|
{
|
||||||
int from = -1;
|
int from = -1;
|
||||||
int to;
|
int to;
|
||||||
@ -39,10 +38,9 @@ namespace anbs_cp
|
|||||||
if (to <= 0)
|
if (to <= 0)
|
||||||
to = astring.Length;
|
to = astring.Length;
|
||||||
if (from != to)
|
if (from != to)
|
||||||
result.Add(astring[from..(to-from)]);
|
result.Add(astring[from..(to - from)]);
|
||||||
from = to;
|
from = to;
|
||||||
} while (to != astring.Length);
|
} while (to != astring.Length);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,41 +1,41 @@
|
|||||||
namespace anbs_cp
|
namespace anbs_cp;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конвертер типов на манер Delphi
|
||||||
|
/// </summary>
|
||||||
|
public static class TypeConverter
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Конвертер типов на манер Delphi
|
|
||||||
/// </summary>
|
|
||||||
public static class TypeConverter
|
|
||||||
{
|
|
||||||
#region Конвертация числа в строку
|
#region Конвертация числа в строку
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Преобразование int в string
|
/// Преобразование int в string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="AInt">Число</param>
|
/// <param name="AInt">Число</param>
|
||||||
/// <returns>Строка</returns>
|
/// <returns>Строка</returns>
|
||||||
public static string IntToStr(int AInt) => AInt.ToString();
|
public static string IntToStr (int AInt) => AInt.ToString();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Преобразование uint в string
|
/// Преобразование uint в string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="AInt">Число</param>
|
/// <param name="AInt">Число</param>
|
||||||
/// <returns>Строка</returns>
|
/// <returns>Строка</returns>
|
||||||
public static string IntToStr(uint AInt) => AInt.ToString();
|
public static string IntToStr (uint AInt) => AInt.ToString();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Преобразование long в string
|
/// Преобразование long в string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="AInt">Число</param>
|
/// <param name="AInt">Число</param>
|
||||||
/// <returns>Строка</returns>
|
/// <returns>Строка</returns>
|
||||||
public static string IntToStr(long AInt) => AInt.ToString();
|
public static string IntToStr (long AInt) => AInt.ToString();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Преобразование ulong в string
|
/// Преобразование ulong в string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="AInt">Число</param>
|
/// <param name="AInt">Число</param>
|
||||||
/// <returns>Строка</returns>
|
/// <returns>Строка</returns>
|
||||||
public static string IntToStr(ulong AInt) => AInt.ToString();
|
public static string IntToStr (ulong AInt) => AInt.ToString();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Преобразование byte в string
|
/// Преобразование byte в string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="AInt">Число</param>
|
/// <param name="AInt">Число</param>
|
||||||
/// <returns>Строка</returns>
|
/// <returns>Строка</returns>
|
||||||
public static string IntToStr(byte AInt) => AInt.ToString();
|
public static string IntToStr (byte AInt) => AInt.ToString();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Конвертация строки в число
|
#region Конвертация строки в число
|
||||||
@ -45,7 +45,7 @@
|
|||||||
/// <param name="AStr">Строка</param>
|
/// <param name="AStr">Строка</param>
|
||||||
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
||||||
/// <returns>Число</returns>
|
/// <returns>Число</returns>
|
||||||
public static int StrToInt(string AStr, int ADefault = 0)
|
public static int StrToInt (string AStr, int ADefault = 0)
|
||||||
{
|
{
|
||||||
if (!int.TryParse(AStr, out int result))
|
if (!int.TryParse(AStr, out int result))
|
||||||
{
|
{
|
||||||
@ -59,7 +59,7 @@
|
|||||||
/// <param name="AStr">Строка</param>
|
/// <param name="AStr">Строка</param>
|
||||||
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
||||||
/// <returns>Число</returns>
|
/// <returns>Число</returns>
|
||||||
public static uint StrToUInt(string AStr, uint ADefault = 0)
|
public static uint StrToUInt (string AStr, uint ADefault = 0)
|
||||||
{
|
{
|
||||||
if (!uint.TryParse(AStr, out uint result))
|
if (!uint.TryParse(AStr, out uint result))
|
||||||
{
|
{
|
||||||
@ -73,7 +73,7 @@
|
|||||||
/// <param name="AStr">Строка</param>
|
/// <param name="AStr">Строка</param>
|
||||||
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
||||||
/// <returns>Число</returns>
|
/// <returns>Число</returns>
|
||||||
public static long StrToInt64(string AStr, long ADefault = 0)
|
public static long StrToInt64 (string AStr, long ADefault = 0)
|
||||||
{
|
{
|
||||||
if (!long.TryParse(AStr, out long result))
|
if (!long.TryParse(AStr, out long result))
|
||||||
{
|
{
|
||||||
@ -87,7 +87,7 @@
|
|||||||
/// <param name="AStr">Строка</param>
|
/// <param name="AStr">Строка</param>
|
||||||
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
||||||
/// <returns>Число</returns>
|
/// <returns>Число</returns>
|
||||||
public static ulong StrToUInt64(string AStr, ulong ADefault = 0)
|
public static ulong StrToUInt64 (string AStr, ulong ADefault = 0)
|
||||||
{
|
{
|
||||||
if (!ulong.TryParse(AStr, out ulong result))
|
if (!ulong.TryParse(AStr, out ulong result))
|
||||||
{
|
{
|
||||||
@ -101,7 +101,7 @@
|
|||||||
/// <param name="AStr">Строка</param>
|
/// <param name="AStr">Строка</param>
|
||||||
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
||||||
/// <returns>Число</returns>
|
/// <returns>Число</returns>
|
||||||
public static byte StrToByte(string AStr, byte ADefault = 0)
|
public static byte StrToByte (string AStr, byte ADefault = 0)
|
||||||
{
|
{
|
||||||
if (!byte.TryParse(AStr, out byte result))
|
if (!byte.TryParse(AStr, out byte result))
|
||||||
{
|
{
|
||||||
@ -110,5 +110,4 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Version>1.20211111.0</Version>
|
<Version>1.2021.1113</Version>
|
||||||
<Authors>Alexander Babaev</Authors>
|
<Authors>Alexander Babaev</Authors>
|
||||||
<Product>ANB Software Components Pack</Product>
|
<Product>ANB Software Components Pack</Product>
|
||||||
<Description>Library of some useful functions in C# language.</Description>
|
<Description>Library of some useful functions in C# language.</Description>
|
||||||
@ -15,8 +15,8 @@
|
|||||||
<SignAssembly>False</SignAssembly>
|
<SignAssembly>False</SignAssembly>
|
||||||
<PackageProjectUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</RepositoryUrl>
|
<RepositoryUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</RepositoryUrl>
|
||||||
<AssemblyVersion>1.2021.1111</AssemblyVersion>
|
<AssemblyVersion>1.2021.1113</AssemblyVersion>
|
||||||
<FileVersion>1.2021.1111</FileVersion>
|
<FileVersion>1.2021.1113</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
13
demo/CountValueTest.Designer.cs
generated
13
demo/CountValueTest.Designer.cs
generated
@ -1,7 +1,7 @@
|
|||||||
namespace demo
|
namespace demo;
|
||||||
|
|
||||||
|
partial class CountValueTest
|
||||||
{
|
{
|
||||||
partial class CountValueTest
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -11,7 +11,7 @@
|
|||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose (bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null))
|
||||||
{
|
{
|
||||||
@ -26,7 +26,7 @@
|
|||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent ()
|
||||||
{
|
{
|
||||||
this.InsertDataLabel = new System.Windows.Forms.Label();
|
this.InsertDataLabel = new System.Windows.Forms.Label();
|
||||||
this.InsertDataBox = new System.Windows.Forms.TextBox();
|
this.InsertDataBox = new System.Windows.Forms.TextBox();
|
||||||
@ -62,7 +62,7 @@
|
|||||||
this.ResultLabel.Size = new System.Drawing.Size(270, 79);
|
this.ResultLabel.Size = new System.Drawing.Size(270, 79);
|
||||||
this.ResultLabel.TabIndex = 2;
|
this.ResultLabel.TabIndex = 2;
|
||||||
this.ResultLabel.Text = "&Insert any int value to insert box above and press \"Calculate\" button to see res" +
|
this.ResultLabel.Text = "&Insert any int value to insert box above and press \"Calculate\" button to see res" +
|
||||||
"ult...";
|
"ult...";
|
||||||
this.ResultLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
this.ResultLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
//
|
//
|
||||||
// CalculateButton
|
// CalculateButton
|
||||||
@ -130,5 +130,4 @@
|
|||||||
private Button CalculateButton;
|
private Button CalculateButton;
|
||||||
private Label SelectFormatterLabel;
|
private Label SelectFormatterLabel;
|
||||||
private ComboBox SelectFormatterBox;
|
private ComboBox SelectFormatterBox;
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,42 +1,32 @@
|
|||||||
using anbs_cp;
|
using anbs_cp;
|
||||||
namespace demo
|
|
||||||
|
namespace demo;
|
||||||
|
|
||||||
|
public partial class CountValueTest: Form
|
||||||
{
|
{
|
||||||
public partial class CountValueTest : Form
|
public CountValueTest ()
|
||||||
{
|
|
||||||
public CountValueTest()
|
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CalculateButton_Click(object sender, EventArgs e)
|
private void CalculateButton_Click (object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(InsertDataBox.Text))
|
if (string.IsNullOrEmpty(InsertDataBox.Text))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IValueFormatter formatter;
|
|
||||||
|
|
||||||
long value = TypeConverter.StrToInt64(InsertDataBox.Text);
|
long value = TypeConverter.StrToInt64(InsertDataBox.Text);
|
||||||
|
IValueFormatter formatter = SelectFormatterBox.SelectedIndex switch
|
||||||
switch (SelectFormatterBox.SelectedIndex)
|
|
||||||
{
|
{
|
||||||
case 0:
|
0 => new CountFormatter(),
|
||||||
formatter = new CountFormatter();
|
1 => new FileSizeFormatter(),
|
||||||
break;
|
_ => new CountFormatter(),
|
||||||
case 1:
|
};
|
||||||
formatter = new FileSizeFormatter();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
formatter = new CountFormatter();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultLabel.Text = formatter.Format(value);
|
ResultLabel.Text = formatter.Format(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CountValueTest_Load(object sender, EventArgs e)
|
private void CountValueTest_Load (object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SelectFormatterBox.SelectedIndex = 0;
|
SelectFormatterBox.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,15 +1,14 @@
|
|||||||
namespace demo
|
namespace demo;
|
||||||
|
|
||||||
|
internal static class Program
|
||||||
{
|
{
|
||||||
internal static class Program
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main ()
|
||||||
{
|
{
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new CountValueTest());
|
Application.Run(new CountValueTest());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user