20230102
This commit is contained in:
parent
af7a5dd299
commit
a2990fe1ef
@ -14,7 +14,8 @@ public sealed class CountConverter : ValueConverter
|
|||||||
/// Конструктор класса
|
/// Конструктор класса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="valueNames">Массив имён размерностей</param>
|
/// <param name="valueNames">Массив имён размерностей</param>
|
||||||
public CountConverter (string[] valueNames) : base(valueNames, 1000)
|
/// <param name="decimalPlace">Знаков после запятой (0, 1, 2)</param>
|
||||||
|
public CountConverter (string[] valueNames, byte decimalPlace = 0) : base(valueNames, 1000, decimalPlace)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,8 @@ public sealed class FileSizeConverter : ValueConverter
|
|||||||
/// Конструктор класса
|
/// Конструктор класса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="valueNames">Массив имён размерностей</param>
|
/// <param name="valueNames">Массив имён размерностей</param>
|
||||||
public FileSizeConverter (string[] valueNames) : base(valueNames, 1024)
|
/// <param name="decimalPlace">Знаков после запятой (0, 1, 2)</param>
|
||||||
|
public FileSizeConverter (string[] valueNames, byte decimalPlace = 2) : base(valueNames, 1024, decimalPlace)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,12 @@ public abstract class ValueConverter: IValueConverter
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="valueNames">Массив имён размерностей</param>
|
/// <param name="valueNames">Массив имён размерностей</param>
|
||||||
/// <param name="divider">Делитель</param>
|
/// <param name="divider">Делитель</param>
|
||||||
protected ValueConverter (string[] valueNames, long divider)
|
/// <param name="decimalPlaces">Число знаков после запятой</param>
|
||||||
|
protected ValueConverter (string[] valueNames, long divider, byte decimalPlaces)
|
||||||
{
|
{
|
||||||
ValueNames = valueNames;
|
ValueNames = valueNames;
|
||||||
Divider = divider;
|
Divider = divider;
|
||||||
|
DecimalPlaces = (byte)(decimalPlaces < 3 ? decimalPlaces : 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Реализация интерфейса
|
#region Реализация интерфейса
|
||||||
@ -28,6 +30,12 @@ public abstract class ValueConverter: IValueConverter
|
|||||||
/// Делитель
|
/// Делитель
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long Divider { get; init; }
|
public long Divider { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Знаков после запятой (0, 1, 2)
|
||||||
|
/// </summary>
|
||||||
|
public byte DecimalPlaces { get; init; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Методы
|
#region Методы
|
||||||
@ -38,9 +46,18 @@ public abstract class ValueConverter: IValueConverter
|
|||||||
/// <returns>Конвертирование значение в строку</returns>
|
/// <returns>Конвертирование значение в строку</returns>
|
||||||
public string Convert (long value)
|
public string Convert (long value)
|
||||||
{
|
{
|
||||||
|
//Получаю разделенное значение
|
||||||
(decimal, int) result = DivideIt(value, 0);
|
(decimal, int) result = DivideIt(value, 0);
|
||||||
|
|
||||||
return $"{result.Item1:F2} {ValueNames[result.Item2]}";
|
//Преобразую значение в строку
|
||||||
|
string resultValue = DecimalPlaces switch {
|
||||||
|
0 => $"{result.Item1:F0}",
|
||||||
|
1 => $"{result.Item1:F1}",
|
||||||
|
_ => $"{result.Item1:F2}"
|
||||||
|
};
|
||||||
|
|
||||||
|
//Возвращаю результат
|
||||||
|
return $"{resultValue} {ValueNames[result.Item2]}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -65,8 +82,6 @@ public abstract class ValueConverter: IValueConverter
|
|||||||
|
|
||||||
//... и продолжаем цикл
|
//... и продолжаем цикл
|
||||||
return DivideIt(value / Divider, count);
|
return DivideIt(value / Divider, count);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
@ -14,4 +14,9 @@ public interface IValueConverter
|
|||||||
/// Делитель
|
/// Делитель
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long Divider { get; init; }
|
public long Divider { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Знаков после запятой (0, 1, 2)
|
||||||
|
/// </summary>
|
||||||
|
public byte DecimalPlaces { get; init; }
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<Version>2022.1224.1</Version>
|
<Version>2023.102.0</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>True</SignAssembly>
|
<SignAssembly>True</SignAssembly>
|
||||||
<PackageProjectUrl>https://git.babaev-an.ru/babaev-an/anbsoftware_componentspack</PackageProjectUrl>
|
<PackageProjectUrl>https://git.babaev-an.ru/babaev-an/anbsoftware_componentspack</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://git.babaev-an.ru/babaev-an/anbsoftware_componentspack</RepositoryUrl>
|
<RepositoryUrl>https://git.babaev-an.ru/babaev-an/anbsoftware_componentspack</RepositoryUrl>
|
||||||
<AssemblyVersion>2022.1224.1</AssemblyVersion>
|
<AssemblyVersion>2023.102.0</AssemblyVersion>
|
||||||
<FileVersion>2022.1224.1</FileVersion>
|
<FileVersion>2023.102.0</FileVersion>
|
||||||
<PackageId>ANBSoftware.ComponentsPack</PackageId>
|
<PackageId>ANBSoftware.ComponentsPack</PackageId>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<AnalysisLevel>6.0</AnalysisLevel>
|
<AnalysisLevel>6.0</AnalysisLevel>
|
||||||
@ -44,6 +44,7 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="System.Text.Encodings.Web" Version="7.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0421_043E_0437_0434_0430_0451_043C/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0421_043E_0437_0434_0430_0451_043C/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0432_0432_0435_0434_0451_043D/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0432_0432_0435_0434_0451_043D/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0438_043C_0451_043D/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0438_043C_0451_043D/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0447_0451_0442/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0447_0451_0442_0447_0438_043A/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0447_0451_0442_0447_0438_043A/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0445_044D_0448_0430/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0445_044D_0448_0430/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0445_044D_0448_0435_043C/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0445_044D_0448_0435_043C/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
Loading…
x
Reference in New Issue
Block a user