Sic.Framework-Nanjing-Baishi/MECF.Framework.Common/Aitex/Core/RT/DataCollection/HighPerformance/DataRecorderHelper.cs

31 lines
866 B
C#

using System;
using System.Collections.Generic;
using SciChart.Core.Extensions;
namespace Aitex.Core.RT.DataCollection.HighPerformance;
public class DataRecorderHelper
{
public static readonly IEnumerable<Type> SupportedValueTypes =
[typeof(bool), typeof(double), typeof(float), typeof(int), typeof(short), typeof(ushort)];
public static string Format<T>(T value)
{
if (value is bool b)
return b ? "'1'" : "'0'";
if (value is float or double)
{
var dVal = Convert.ToDouble(value);
return dVal.IsNaN() ? "'0.0'" : $"'{value}'";
}
if (value is int or ushort or short)
{
var iVal = Convert.ToInt32(value);
return $"'{value}'";
}
throw new InvalidCastException("unknown type of data to be cached.");
}
}