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