修改为单屏
This commit is contained in:
@@ -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();
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user