DeviceManager/TsSFCDeivceClient/Model/APIResponseData.cs
2024-05-29 09:56:37 +08:00

95 lines
2.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Newtonsoft.Json;
using System;
namespace TsSFCDeivceClient.Model
{
public class APIResponseData
{
/// <summary>
/// 状态码
/// </summary>
public int Code { get; set; } = 200;
/// <summary>
/// 返回的数据
/// </summary>
public object Data { get; set; }
/// <summary>
/// 错误消息
/// </summary>
public string Message { get; set; }
/// <summary>
/// 登录返回的Token其他方法不返回
/// </summary>
public string Token { get; set; }
/// <summary>
/// 操作是否成功
/// </summary>
public bool IsSuccess
{
get
{
return Code == 1;
}
}
/// <summary>
/// 结果转整数型
/// </summary>
/// <returns></returns>
public int ToInt()
{
try
{
if (Code == 1)
return Convert.ToInt32(Data);
throw new Exception(Message);
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 结果转布尔类型
/// </summary>
/// <returns></returns>
public bool ToBool()
{
try
{
if (Code == 1)
return (bool)Data;
throw new Exception(Message);
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 结果转对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T ToDeserializeObject<T>()
{
try
{
if (Data == null)
return default(T);
return JsonConvert.DeserializeObject<T>(Data + "");
}
catch (Exception)
{
throw;
}
}
}
}