using Nancy.Swagger.Annotations.Attributes; using System; using System.Linq; using System.Text; using 电子展板.Base; namespace 电子展板.Models { /// /// 配置类 /// [Model("配置项")] public class MyConfig : ModelBase { /// /// 时间 /// [Comment("时间")] [ModelProperty(Description = "时间", Required = true)] public string Time { get; set; } /// /// 时间字体大小 /// [Comment("时间字体大小")] [ModelProperty(Description = "时间字体大小", Required = true, Minimum = 15, Maximum = 60)] public int TimeSize { get; set; } /// /// 负责人 /// [Comment("负责人")] [ModelProperty(Description = "负责人", Required = true)] public string Charger { get; set; } /// /// 负责人字体大小 /// [Comment("负责人字体大小")] [ModelProperty(Description = "负责人字体大小", Required = true, Minimum = 15, Maximum = 60)] public int ChargerSize { get; set; } /// /// 风险等级 /// [Comment("风险等级")] [ModelProperty(Description = "风险等级", Required = true)] public string RiskLevel { get; set; } /// /// 风险等级字体大小 /// [Comment("风险等级字体大小")] [ModelProperty(Description = "风险等级字体大小", Required = true, Minimum = 15, Maximum = 60)] public int RiskLevelSize { get; set; } /// /// 工作内容 /// [Comment("工作内容")] [ModelProperty(Description = "工作内容", Required = true)] public string Content { get; set; } /// /// 工作内容字体大小 /// [Comment("工作内容字体大小")] [ModelProperty(Description = "工作内容字体大小", Required = true, Minimum = 15, Maximum = 60)] public int ContentSize { get; set; } /// /// 危险点 /// [Comment("危险点")] [ModelProperty(Description = "危险点", Required = true)] public string DangerPoint { get; set; } /// /// 危险点 /// [Comment("危险点字体大小")] [ModelProperty(Description = "危险点字体大小", Required = true, Minimum = 15, Maximum = 60)] public int DangerPointSize { get; set; } /// /// 重点措施 /// [Comment("重点措施")] [ModelProperty(Description = "重点措施", Required = true)] public string Measures { get; set; } [Comment("重点措施字体大小")] [ModelProperty(Description = "重点措施字体大小", Required = true)] public int MeasuresSize { get; set; } [Comment("党员1图片路径")] [ModelProperty(Description = "党员1图片路径", Required = true)] public string CPCMember1Path { get; set; } [Comment("党员1姓名")] [ModelProperty(Description = "党员1姓名", Required = true)] public string CPCMember1Name { get; set; } [Comment("党员2图片路径")] [ModelProperty(Description = "党员2图片路径", Required = true)] public string CPCMember2Path { get; set; } [Comment("党员2姓名")] [ModelProperty(Description = "党员2姓名", Required = true)] public string CPCMember2Name { get; set; } [Comment("党员3图片路径")] [ModelProperty(Description = "党员3图片路径", Required = true)] public string CPCMember3Path { get; set; } [Comment("党员3姓名")] [ModelProperty(Description = "党员3姓名", Required = true)] public string CPCMember3Name { get; set; } [Comment("党员4图片路径")] [ModelProperty(Description = "党员4图片路径", Required = true)] public string CPCMember4Path { get; set; } [Comment("党员4姓名")] [ModelProperty(Description = "党员4姓名", Required = true)] public string CPCMember4Name { get; set; } [Comment("党员字体大小")] [ModelProperty(Description = "党员字体大小", Required = true, Minimum = 15, Maximum = 60)] public int CPCMemberSize { get; set; } /// /// 转换成JSON字符串 /// /// //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)) // { // string value1 = (string)value; // value1 = value1.Replace("\"", "\\\""); // value1 = value1.Replace("\r\n", "\\r\\n"); // sb.AppendLine($" \"{propertyName}\":\"{value1}\"{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; } } }