Files
daluandou/.codely.packages/cn.tuanjie.codely.bridge@1.0.85-47f31100/Editor/Bridge/Helpers/JsonCommandHelper.cs
T
huadexuan 13d0c80335 ```
chore(bridge): 删除桥接包的提交记录和Git属性配置

删除了 .codely-bridge-commit 文件中存储的提交哈希值
移除了 .gitattributes 文件中的行结束符配置规则
```
2026-09-24 21:41:14 +08:00

72 lines
2.0 KiB
C#

using System;
using System.Linq;
using Codely.Newtonsoft.Json.Linq;
namespace UnityTcp.Editor.Helpers
{
/// <summary>
/// Helper class for JSON command processing utilities
/// </summary>
public static class JsonCommandHelper
{
/// <summary>
/// Helper method to check if a string is valid JSON
/// </summary>
public static bool IsValidJson(string text)
{
if (string.IsNullOrWhiteSpace(text))
{
return false;
}
text = text.Trim();
if (
(text.StartsWith("{") && text.EndsWith("}"))
|| // Object
(text.StartsWith("[") && text.EndsWith("]"))
) // Array
{
try
{
JToken.Parse(text);
return true;
}
catch
{
return false;
}
}
return false;
}
/// <summary>
/// Helper method to get a summary of parameters for error reporting
/// </summary>
public static string GetParamsSummary(JObject @params)
{
try
{
return @params == null || !@params.HasValues
? "No parameters"
: string.Join(
", ",
@params
.Properties()
.Select(p =>
{
string s = p.Value?.ToString();
if (s == null) return $"{p.Name}: ";
int take = Math.Min(20, s.Length);
return $"{p.Name}: {s.Substring(0, take)}";
})
);
}
catch
{
return "Could not summarize parameters";
}
}
}
}