这应该很容易。我有一个字符串,像下面这样进行转义:
string originalString = "M&M";
string escapedString = System.Security.SecurityElement.Escape(originalString);//M&M
迄今为止还不错
string unEscapedString = System.Security.SecurityElement.FromString(escapedString).Text;
期望回到 M&M 但收到 "对象未设置" 的错误消息。
假设字符串应该采用 XML 格式,因此在这种情况下需要什么帮助。
System.Security.SecurityElement.FromString()
不会返回一个string
,你把它的结果赋值给了一个string
,这是打错了吗? - cliesensFromString
方法需要 XML 格式的字符串作为输入;例如string unEscapedString = System.Security.SecurityElement.FromString($"<elementName>{escapedString}</elementName>");
。 - quaabaamFromString
的作用是从 XML 字符串中获取SecurityElement
对象,而不是将值解码为字符串。因此,在 'SecurityElement' 对象中技术上没有 _decode_。有一个辅助方法来编码值是有意义的,但是没有解码它,因为您希望SecurityElement
对象能够正常工作。 - quaabaam