C# 接口设计:IResultModel 和 IResultModel<T> 用于返回结果
using System; using System.Collections.Generic; using System.Text; using Newtonsoft.Json;
namespace ShenGoArchive
{
///
/// <summary>
/// 错误
/// </summary>
string Msg { get; }
}
/// <summary>
/// 返回结果模型泛型接口
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IResultModel<T> : IResultModel
{
/// <summary>
/// 返回数据
/// </summary>
T Data { get; }
}
}
取Data值内容:需要通过实例化实现IResultModel
// 假设返回结果为ResultModel<T>类型
var result = new ResultModel<string> { Successful = true, Data = 'Hello World' };
if (result.Successful)
{
Console.WriteLine(result.Data); // 输出 'Hello World'
}
原文地址: https://www.cveoy.top/t/topic/ofGw 著作权归作者所有。请勿转载和采集!