Sic.Framework-Nanjing-Baishi/MECF.Framework.Common/Aitex/Core/RT/IOCore/Interlock/DataProvider/BoolDataPollProvider.cs

34 lines
1.1 KiB
C#
Raw Normal View History

using System;
using System.Diagnostics;
using Aitex.Core.RT.DataCenter;
namespace Aitex.Core.RT.IOCore.Interlock.DataProvider;
public class BoolDataPollProvider : DataPollProviderBase<bool>, IInterlockLimitDataProvider
{
public BoolDataPollProvider(string dataPath) : base(dataPath)
{
}
/// <summary>
/// <inheritdoc cref="DataPollProviderBase{T}.HandleGetValue"/>
/// </summary>
/// <returns></returns>
/// <exception cref="NullReferenceException"></exception>
/// <exception cref="InvalidCastException"></exception>
protected override object HandleGetValue()
{
var value = DATA.Poll(DataPath);
Debug.Assert(value != null, $"the return value of {DataPath} is null.");
Debug.Assert(bool.TryParse(value.ToString(), out _), $"the return value of {DataPath} is not boolean.");
if (value == null)
throw new NullReferenceException($"the return value of {DataPath} is null.");
if (bool.TryParse(value.ToString(), out var bValue))
return bValue;
throw new InvalidCastException($"the return value of {DataPath} is not bool.");
}
}