修改为单屏

This commit is contained in:
2025-09-26 11:23:55 +08:00
parent aa43943f33
commit 0884292626
11 changed files with 223 additions and 420 deletions

View File

@@ -122,44 +122,47 @@ namespace 电子展板.Models
/// 转换成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 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();
//}
}