gpt4 book ai didi

C# - 如何在 Dotfuscator.Net 中使用匿名类型?

转载 作者:行者123 更新时间:2023-11-30 21:44:53 26 4
gpt4 key购买 nike

我的 C# 应用程序中有这段代码:

JObject personJson = JObject.FromObject(
new
{
name = "John Doe",
age = 34,
height = 1.78,
weight = 79.34
});

Console.WriteLine(person);

它记录:

{
"name": "John Doe",
"age": 34,
"height": 1.78,
"weight": 79.34
}

Dotfuscater 将其混淆为:

Console.WriteLine((object) JObject.FromObject((object) new global::b<string, int, double, double>("John Doe", 34, 1.78, 79.34)));

然后输出是这样的:

{}

如何在 Dotfuscator 中使用匿名类而不出现此问题?

编辑:

完整代码:

public static class Example
{
static void LogPerson()
{
JObject personJson = JObject.FromObject(
new
{
name = "John Doe",
age = 34,
height = 1.78,
weight = 79.34
});
Console.WriteLine(JSONObject);
}
}

最佳答案

你/我可以使用一个动态对象,像这样:

dynamic person = new ExpandoObject();
person.name = "John Doe";
person.age = 34;
person.height = 1.78;
person.weight = 79.34;

JObject personJson = JObject.FromObject(person);

Console.WriteLine(personJson);

混淆后看起来很奇怪,但确实有效。输出完全符合预期。

关于C# - 如何在 Dotfuscator.Net 中使用匿名类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40561448/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com