新增SwaggerDemo
This commit is contained in:
174
电子展板/Models/MyConfig.cs
Normal file
174
电子展板/Models/MyConfig.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using 电子展板.Base;
|
||||
using 电子展板.Utility.Swagger;
|
||||
|
||||
namespace 电子展板.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置类
|
||||
/// </summary>
|
||||
[SwaggerClassComment("配置项")]
|
||||
public class MyConfig : ModelBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 时间
|
||||
/// </summary>
|
||||
[Comment("时间")]
|
||||
[SwaggerComment("时间", true)]
|
||||
public string Time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 时间字体大小
|
||||
/// </summary>
|
||||
[Comment("时间字体大小")]
|
||||
[SwaggerComment("时间字体大小", true, 15, 60)]
|
||||
public int TimeSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 负责人
|
||||
/// </summary>
|
||||
[Comment("负责人")]
|
||||
[SwaggerComment("负责人", true)]
|
||||
public string Charger { get; set; }
|
||||
/// <summary>
|
||||
/// 负责人字体大小
|
||||
/// </summary>
|
||||
[Comment("负责人字体大小")]
|
||||
[SwaggerComment("负责人字体大小", true, 15, 60)]
|
||||
public int ChargerSize { get; set; }
|
||||
/// <summary>
|
||||
/// 风险等级
|
||||
/// </summary>
|
||||
[Comment("风险等级")]
|
||||
[SwaggerComment("风险等级", true)]
|
||||
public string RiskLevel { get; set; }
|
||||
/// <summary>
|
||||
/// 风险等级字体大小
|
||||
/// </summary>
|
||||
[Comment("风险等级字体大小")]
|
||||
[SwaggerComment("风险等级字体大小", true, 15, 60)]
|
||||
public int RiskLevelSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工作内容
|
||||
/// </summary>
|
||||
[Comment("工作内容")]
|
||||
[SwaggerComment("工作内容", true)]
|
||||
public string Content { get; set; }
|
||||
/// <summary>
|
||||
/// 工作内容字体大小
|
||||
/// </summary>
|
||||
[Comment("工作内容字体大小")]
|
||||
[SwaggerComment("工作内容字体大小", true, 15, 60)]
|
||||
public int ContentSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 危险点
|
||||
/// </summary>
|
||||
[Comment("危险点")]
|
||||
[SwaggerComment("危险点", true)]
|
||||
public string DangerPoint { get; set; }
|
||||
/// <summary>
|
||||
/// 危险点
|
||||
/// </summary>
|
||||
[Comment("危险点字体大小")]
|
||||
[SwaggerComment("危险点字体大小", true, 15, 60)]
|
||||
public int DangerPointSize { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重点措施
|
||||
/// </summary>
|
||||
[Comment("重点措施")]
|
||||
[SwaggerComment("重点措施", true)]
|
||||
public string Measures { get; set; }
|
||||
|
||||
[Comment("重点措施字体大小")]
|
||||
public int MeasuresSize { get; set; }
|
||||
|
||||
[Comment("党员1图片路径")]
|
||||
[SwaggerComment("党员1图片路径", true)]
|
||||
public string CPCMember1Path { get; set; }
|
||||
[Comment("党员1姓名")]
|
||||
[SwaggerComment("党员1姓名", true)]
|
||||
public string CPCMember1Name { get; set; }
|
||||
[Comment("党员2图片路径")]
|
||||
[SwaggerComment("党员2图片路径", true)]
|
||||
public string CPCMember2Path { get; set; }
|
||||
[Comment("党员2姓名")]
|
||||
[SwaggerComment("党员2姓名", true)]
|
||||
public string CPCMember2Name { get; set; }
|
||||
[Comment("党员3图片路径")]
|
||||
[SwaggerComment("党员3图片路径", true)]
|
||||
public string CPCMember3Path { get; set; }
|
||||
|
||||
[Comment("党员3姓名")]
|
||||
[SwaggerComment("党员3姓名", true)]
|
||||
public string CPCMember3Name { get; set; }
|
||||
[Comment("党员4图片路径")]
|
||||
[SwaggerComment("党员4图片路径", true)]
|
||||
public string CPCMember4Path { get; set; }
|
||||
[Comment("党员4姓名")]
|
||||
[SwaggerComment("党员4姓名", true)]
|
||||
public string CPCMember4Name { get; set; }
|
||||
|
||||
[Comment("党员字体大小")]
|
||||
[SwaggerComment("党员字体大小", true, 15, 60)]
|
||||
public int CPCMemberSize { get; set; }
|
||||
/// <summary>
|
||||
/// 转换成JSON字符串
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ToJson()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("{");
|
||||
//得到所有的Property
|
||||
var properties = GetType().GetProperties();
|
||||
for (int i = 0; i < properties.Length; i++)
|
||||
{
|
||||
var property = properties[i];
|
||||
string endChar = ",";
|
||||
if (i == properties.Length - 1)
|
||||
{
|
||||
endChar = "";
|
||||
}
|
||||
var comment = property.GetCustomAttributes(typeof(CommentAttribute), false).FirstOrDefault() as CommentAttribute;
|
||||
string commentText = "";
|
||||
if (comment != null)
|
||||
{
|
||||
commentText = $" /* {comment.Comment} */";
|
||||
}
|
||||
string propertyName = property.Name;
|
||||
var value = property.GetValue(this, null);
|
||||
if (value != null)
|
||||
{
|
||||
var valueType = value.GetType();
|
||||
if (valueType == typeof(string))
|
||||
{
|
||||
sb.AppendLine($" \"{propertyName}\":\"{value}\"{endChar}{commentText}");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine($" \"{propertyName}\":{value}{endChar}{commentText}");
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.AppendLine("}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class CommentAttribute : Attribute
|
||||
{
|
||||
public string Comment { get; set; }
|
||||
public CommentAttribute(string comment)
|
||||
{
|
||||
Comment = comment;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
20
电子展板/Models/RetValue.cs
Normal file
20
电子展板/Models/RetValue.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using 电子展板.Utility.Swagger;
|
||||
|
||||
namespace 电子展板.Models
|
||||
{
|
||||
[SwaggerClassComment("返回数据")]
|
||||
public class RetValue
|
||||
{
|
||||
[SwaggerComment("返回状态")]
|
||||
public int state { get; set; }
|
||||
[SwaggerComment("返回消息")]
|
||||
public string message { get; set; }
|
||||
[SwaggerComment("返回数据")]
|
||||
public object data { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user