C# 从case语句C中获取数据#

C# 从case语句C中获取数据#,c#,.net,wpf,sdk,switch-statement,C#,.net,Wpf,Sdk,Switch Statement,我用的是我们买的一个热摄像头的SDK。实际上,我是一名PHP Web开发人员,现在我必须在.Net中编写代码 所以有一个案例,但我真的不知道如何从中获取数据 private void OnDetect(CallbackEventArgument callbackArgument) { var detectionResult = callbackArgument.GetDetectionResult(); var firstDetection = detectionResult

我用的是我们买的一个热摄像头的SDK。实际上,我是一名PHP Web开发人员,现在我必须在.Net中编写代码

所以有一个案例,但我真的不知道如何从中获取数据

 private void OnDetect(CallbackEventArgument callbackArgument)
 {
    var detectionResult = callbackArgument.GetDetectionResult();
    var firstDetection = detectionResult.Sequence.Items.First();

    var message = string.Empty;
    ImageArgument fullSizeImage = null;
    switch (detectionResult.Type)
    {
       case T3DDetectionType.OBSERVATION:
          message = "Track ID: " + firstDetection.TrackId;
          fullSizeImage = detectionResult.RGBImage;
          break;
       case T3DDetectionType.DEPTH_LIVENESS:
       case T3DDetectionType.THERMAL_LIVENESS:
          message = "Track ID: " + firstDetection.TrackId + " Score: " + (firstDetection as Liveness).Score.ToString("N0");
          fullSizeImage = detectionResult.FullImage;
          break;
       case T3DDetectionType.TEMPERATURE:
          message = "Temperature: " + (firstDetection as Temperature).MeasurementValueCelsius.ToString("N1") + "°C";
          fullSizeImage = detectionResult.FullImage;
          break;
    }
因此,我想做的是能够获得
(firstDetection作为Liveness)的数据。Score.ToString(“N0”)
firstDetection.TrackId
(firstDetection作为温度)。measurementValueCelsium.ToString(“N1”)+“°C”
在case之后创建一个JSON


创建json是可行的,但我无法调用数据。

如果您想从switch语句中得到一些东西,只需执行以下操作:

  • 在switch语句之前声明一个变量
  • 并将所需的值指定给开关盒内的变量

现在,在switch语句之后,您将在变量
firstDetection

中获得所需的值,这是什么意思?你想得到在case
T3DDetectionType.DEPTH\u LIVENESS:
?我想得到
(第一次检测为温度)的值。MeasurementValueCelsius.ToString(“N1”)
,不要介意Json。我只想在switch语句中使用这个变量的数据,在c#中创建json字符串时,我会考虑序列化。构建一个对象并序列化为json。不过,我在里面看到了一些非常奇怪的东西。您要以json格式发送图片吗?我希望有一个枚举。你为什么关心字符串格式?我希望这是接收json的任何人的工作。奇怪的是,你也有不同的变量。这将是一个不同的类序列化或可能只是一个。
string firstDetection = string.Empty;
case T3DDetectionType.TEMPERATURE:
   message = "Temperature: " + (firstDetection as Temperature).MeasurementValueCelsius.ToString("N1") + "°C";
   firstDetection = (firstDetection as Temperature).MeasurementValueCelsius.ToString("N1") + "°C";
   fullSizeImage = detectionResult.FullImage;
   break;