@using Salmon.Core.Cliff
@if(Value is null)
{
(null)
}
else
{
if(Value is bool b)
{
if(b)
{
true
}
else
{
false
}
}
else if (IsIntegerType(Value))
{
@PrettifyInteger(Value)
}
else if (IsFloatingType(Value))
{
@PrettifyFloating(Value)
}
else if (Predicate is not null && Predicate == "parent")
{
@Value.ToString()
}
else if (Predicate is not null && Predicate == "Uri")
{
@Value.ToString()
}
else
{
@Value.ToString()
}
}
@code {
[Parameter]
public object? Value { get; set; }
[Parameter]
public string Predicate { get; set; }
public static bool IsNumericType(object o)
{
switch (Type.GetTypeCode(o.GetType()))
{
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.Decimal:
case TypeCode.Double:
case TypeCode.Single:
return true;
default:
return false;
}
}
public static bool IsFloatingType(object o)
{
switch (Type.GetTypeCode(o.GetType()))
{
case TypeCode.Decimal:
case TypeCode.Double:
case TypeCode.Single:
return true;
default:
return false;
}
}
public static bool IsIntegerType(object o)
{
switch (Type.GetTypeCode(o.GetType()))
{
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
return true;
default:
return false;
}
}
public static string PrettifyFloating(object o)
{
switch (Type.GetTypeCode(o.GetType()))
{
case TypeCode.Decimal:
return ((Decimal)o).ToString("### ### ### ### ### ###");
case TypeCode.Double:
return ((Double)o).ToString("### ### ### ### ### ###");
case TypeCode.Single:
return ((Single)o).ToString("### ### ### ### ### ###");
default:
throw new ArgumentException();
}
}
public static string PrettifyInteger(object o)
{
switch (Type.GetTypeCode(o.GetType()))
{
case TypeCode.Byte:
case TypeCode.SByte:
return o.ToString();
case TypeCode.UInt16:
return ((UInt16)o).ToString("# ###");
case TypeCode.UInt32:
return ((UInt32)o).ToString("# ###");
case TypeCode.UInt64:
return ((UInt64)o).ToString("# ###");
case TypeCode.Int16:
return ((Int16)o).ToString("# ###");
case TypeCode.Int32:
return ((Int32)o).ToString("# ###");
case TypeCode.Int64:
return ((Int64)o).ToString("# ###");
default:
throw new ArgumentException();
}
}
}