Skip to content
Taiizor edited this page Mar 1, 2023 · 35 revisions

Detect Class - Skylark.Helper Namespace

The Detect class provides static methods and properties for detecting the decimal separator character in the current culture.

Methods

private static string Formula

Returns a string representation of a division formula, used to determine the separator character used in numerical values.

private static string Formula => $"{10 / 3f}";

Fields

  • Char: Gets the decimal separator character in the current culture.
  • CharCross: Gets the opposite decimal separator character in the current culture.
  • Enum: Gets the SEDT enumeration value that corresponds to the Char field.
  • EnumCross: Gets the SEDT enumeration value that corresponds to the CharCross field.
  • String: Gets the string representation of the Char field.
  • StringCross: Gets the string representation of the CharCross field.

DetectType Enumeration

The SEDT enumeration specifies the type of decimal separator character detected.

public enum DetectType
{
    Dot,
    None,
    Comma
}

Properties

Char

Returns the separator character used in numerical values. If the separator character is a dot ('.'), returns '.'; otherwise, returns ','.

public static char Char => Formula.Contains('.') ? '.' : ',';

CharCross

Returns the opposite separator character of the one used in numerical values. If the separator character is a dot ('.'), returns ','; otherwise, returns '.'.

public static char CharCross => Char == '.' ? ',' : '.';

Enum

Returns the SEDT value that corresponds to the separator character used in numerical values. If the separator character is a dot ('.'), returns SEDT.Dot; if the separator character is a comma (','), returns SEDT.Comma; otherwise, returns SEDT.None.

public static SEDT Enum => Char switch
{
    '.' => SEDT.Dot,
    ',' => SEDT.Comma,
    _ => SEDT.None,
};

EnumCross

Returns the SEDT value that corresponds to the opposite separator character of the one used in numerical values. If the separator character is a dot ('.'), returns SEDT.Comma; if the separator character is a comma (','), returns SEDT.Dot; otherwise, returns SEDT.None.

public static SEDT EnumCross => CharCross switch
{
    '.' => SEDT.Dot,
    ',' => SEDT.Comma,
    _ => SEDT.None,
};

String

Returns a string representation of the separator character used in numerical values. If the separator character is a dot ('.'), returns "."; otherwise, returns ",".

public static string String => $"{Char}";

StringCross

Returns a string representation of the opposite separator character of the one used in numerical values. If the separator character is a dot ('.'), returns ","; otherwise, returns ".".

public static string StringCross => $"{CharCross}";

Example Usage

The following example demonstrates how to use the Detect class to determine the decimal separator character and corresponding enumeration value in the current culture:

// Detect the decimal separator character
char decimalSeparator = Detect.Char;
Console.WriteLine($"Decimal separator: {decimalSeparator}");

// Detect the opposite decimal separator character char oppositeDecimalSeparator = Detect.CharCross; Console.WriteLine($"Opposite decimal separator: {oppositeDecimalSeparator}");

// Detect the decimal separator as an Enum value DetectType decimalSeparatorEnum = Detect.Enum; Console.WriteLine($"Decimal separator Enum: {decimalSeparatorEnum}");

// Detect the opposite decimal separator as an Enum value DetectType oppositeDecimalSeparatorEnum = Detect.EnumCross; Console.WriteLine($"Opposite decimal separator Enum: {oppositeDecimalSeparatorEnum}");

// Get the decimal separator as a string string decimalSeparatorString = Detect.String; Console.WriteLine($"Decimal separator string: {decimalSeparatorString}");

// Get the opposite decimal separator as a string string oppositeDecimalSeparatorString = Detect.StringCross; Console.WriteLine($"Opposite decimal separator string: {oppositeDecimalSeparatorString}");

Clone this wiki locally