Files
radzen-blazor/Radzen.Blazor/Documents/Spreadsheet/FormatCodeBuilder.cs
Atanas Korchev dc699e9518 Remove noise comments and non-public XML docs from spreadsheet code
Two sweeps over Radzen.Blazor/Documents/Spreadsheet and Radzen.Blazor/Spreadsheet:

- Delete inline `//` comments that merely restate the adjacent code
  (e.g. "// Decrease column count" above `ColumnCount--;`, the "// Parse X"
  labels above the matching ParseX(...) calls). Comments explaining *why*,
  Excel/OOXML quirks, ordering requirements and trade-offs are kept.
- Delete XML doc comments (`///`) on non-public declarations — private/internal
  members and the members of internal types (XlsxWriter/Reader, CsvWriter/Reader,
  the formula lexer/parser, the Functions classes, AutofillCommand, etc.). Docs
  on the public API surface are untouched (the build enforces this via CS1591).

Comment-only changes; no behavior change. Build clean, 1477 spreadsheet tests pass.
2026-06-15 18:45:15 +03:00

45 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
namespace Radzen.Documents.Spreadsheet;
#nullable enable
internal static class FormatCodeBuilder
{
public static string Build(NumberFormatCategory category, int decimalPlaces = 2,
bool useThousandsSeparator = true, string currencySymbol = "$",
string? selectedPreset = null)
{
var decimals = decimalPlaces > 0 ? "." + new string('0', decimalPlaces) : "";
return category switch
{
NumberFormatCategory.General => "General",
NumberFormatCategory.Number => (useThousandsSeparator ? "#,##0" : "0") + decimals,
NumberFormatCategory.Currency => currencySymbol + (useThousandsSeparator ? "#,##0" : "0") + decimals,
NumberFormatCategory.Accounting => BuildAccountingFormat(decimalPlaces, currencySymbol),
NumberFormatCategory.Percentage => "0" + decimals + "%",
NumberFormatCategory.Scientific => "0" + decimals + "E+00",
NumberFormatCategory.Date => selectedPreset ?? "mm/dd/yyyy",
NumberFormatCategory.Time => selectedPreset ?? "h:mm AM/PM",
NumberFormatCategory.Text => "@",
_ => "General"
};
}
private static string BuildAccountingFormat(int decimalPlaces, string currencySymbol)
{
var decimals = decimalPlaces > 0 ? "." + new string('0', decimalPlaces) : "";
var pos = $"_({currencySymbol}* #,##0{decimals}_)";
var neg = $"_({currencySymbol}* (#,##0{decimals})";
var zero = decimalPlaces > 0
? $"_({currencySymbol}* \"-\"{new string('?', decimalPlaces)}_)"
: $"_({currencySymbol}* \"-\"_)";
var text = "_(@_)";
return $"{pos};{neg};{zero};{text}";
}
public static IReadOnlyList<string> CurrencySymbols { get; } = ["$", "\u20AC", "\u00A3", "\u00A5"];
}