我目前正在测试一个应用程序,但它向我抛出了一个错误的 JSON 转义序列,但是我没有看到问题......
我可能忽略了一些东西,所以一双新鲜的眼睛可能会有用。
messageContents = "{\"command\":\"cue\",\"channel\":1,\"uid\":\"aesd-deaf\",\"type\":\"standard\",\"waitforexecute\":true,\"duration\":0,\"scene\":[{\"name\":\"Scene1\",\"fields\":[{\"Quad1\":\"F:\\TestFolder\\mill.jpg\"}]}]}";
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
{"Bad JSON escape sequence: \\T. Path 'scene[0].fields[0].Quad1', line 1, position 150."}
Run Code Online (Sandbox Code Playgroud)
任何人都可以发现错误吗?谢谢,肯尼斯
我知道当我迭代IEnumerable时,我会迭代源集合,所以如果我在IEnumerable的下一次迭代中修改了源集合,它就会计算modificaction.
所以当我有一个有序的IEnumerable时,我想知道它是如何影响它的.
例如,如果我有这个:
List<MyType> myNoOrderedList //add my items
IEnumerable<MyType> myOrderedIEnumerable = myNoOrderedList
.OrderBy(x => x.Property);
foreach(MyType in myOrderedIEnumerable)
{
//Do something
}
Run Code Online (Sandbox Code Playgroud)
假设我在列表中有3个元素,在IEnumerable的每次迭代中,列表是有序的还是只列出一次列表?
如果在"做某事"我添加或删除项目会发生什么?IEnumerable有初始订购的商品还是必须再次订购以便对帐户进行修改?
请看一下这些代码:
\n\nstring str_to_find = "\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\\r\\n";\nstring str = "Nancy" + str_to_find;\nif (str.EndsWith(str_to_find)) {\n str = Remove_Last_String(str, str_to_find);\n}\nRun Code Online (Sandbox Code Playgroud)\n\n这是方法:
\n\npublic static string Remove_Last_String(string Source, string Find) {\n int i = Source.LastIndexOf(Find);\n if (i >= 0) {\n string new_str = Source.Substring(0, i);\n return new_str;\n }\n else return Source;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我想要Nancy输出。
\n但是方法返回:
\n Nancy\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96\xe2\x9e\x96
\n这些奇怪的字符有什么问题&我该如何修复它?
对于以下行:
decimal sec = (decimal)TimeSpan.FromMilliseconds(.8).TotalSeconds;
Run Code Online (Sandbox Code Playgroud)
我期望 sec = 0.0008 ,但它被四舍五入到 3 个小数位并给出结果 0.001 ,任何解决方法。
使用以下 C# 控制台应用程序代码,我可以使用 Jenkins 在后台运行该进程。但现在我想在前台看到这个过程。我在这里做错了什么?
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr handle);
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool IsIconic(IntPtr handle);
private void startT32app()
{
IntPtr handle;
try
{
Console.WriteLine("T32 launching");
string path = @"C:\T32\bin\windows64\t32mppc.exe";
string args = @"C:\T32\config.t32";
ProcessStartInfo procInfo = new ProcessStartInfo(path, args);
procInfo.CreateNoWindow = false;
procInfo.UseShellExecute = true;
procInfo.WindowStyle = ProcessWindowStyle.Normal;
Process procRun = Process.Start(procInfo);
handle = procRun.MainWindowHandle;
SetForegroundWindow(handle);
}
catch
{
Console.WriteLine("Failed to launch T32");
}
}
static void …Run Code Online (Sandbox Code Playgroud) 我有一些类具有多个属性,这些属性具有明确定义的名称和功能,但具有相同的实现.例如:
class Stats
{
private int attack;
public int Attack
{
get =>
HasBuff ? attack + 1 : attack;
set
{
if (value < 1 || value > 10)
throw new ArgumentOutOfRangeException("Invalid value");
attack = value;
}
}
public int Defense {...}
public int Speed {...}
}
Run Code Online (Sandbox Code Playgroud)
在哪里Defense和Speed将要实施就像Attack.如何概括此结构以避免冗余并使更改更容易?
我知道有很多这样的问题,但我找不到我想做的事情的任何答案。
考虑以下抽象类:
public abstract class TestBase
{
public static ITest Test => Container.Resolve<ITest>();
public static ITest1 Test1 => Container.Resolve<ITest1>();
public static ITest2 Test2 => Container.Resolve<ITest2>();
public static ITest3 Test3 => Container.Resolve<ITest3>();
}
Run Code Online (Sandbox Code Playgroud)
我试图获取从 IDummy 接口继承的所有属性,如下所示:
var members = typeof(TestBase).GetMembers(BindingFlags.Static | BindingFlags.Public)
.Where(f => f.GetType().IsAssignableFrom(typeof(IDummy)) == true);
Run Code Online (Sandbox Code Playgroud)
但列表是空的。如果不添加 where 子句“ .Where(f => f.GetType().IsAssignableFrom(typeof(IDummy)) == true)”,我会得到所有结果,包括属性的 getter。
可能是一些微不足道的事情,但由于我对反射不太熟悉,我无法弄清楚我做错了什么。
我有一个具有以下签名的异步方法:
public async Task UpdateMerchantAttributes(UpdateMerchantRequestModel model).
Run Code Online (Sandbox Code Playgroud)
该模型只有一个属性:
public Dictionary<string, string> Attributes { get; set; }
Run Code Online (Sandbox Code Playgroud)
有一段时间我用以下方式在测试中调用它:
await client.UpdateMerchantAttributes(new UpdateMerchantRequestModel { Attributes =
{
{"businessType", "0"}
}
});
Run Code Online (Sandbox Code Playgroud)
编译得很好,但NullReferenceException在该行上运行时引起了.我对此感到困惑,因为client它不是null,并且该行中没有引用任何其他内容(或者看起来一目了然).然后我尝试添加一个显式的Dictionary声明,如下所示:
await client.UpdateMerchantAttributes(new UpdateMerchantRequestModel { Attributes =
new Dictionary<string, string>
{
{"businessType", "0"}
}
});
Run Code Online (Sandbox Code Playgroud)
现在它传递得很好.这是我的错误,但如果这是一个编译错误而不是运行时空引用异常,那么这个错误将花费我更少的时间.所以我很好奇,为什么会这样呢?编译器是否认为我正在尝试定义一个dynamic并以某种方式解析为null?
最后,我尝试将一个文件设置为复制到构建输出目录.但我遇到了无法找到项目属性的问题.我知道它应该在那里,我忽略了什么?
我遵循本指南:https://docs.microsoft.com/nl-nl/cpp/ide/general-property-page-project 在第一行中它建议:
在解决方案资源管理器中右键单击项目节点,然后选择"属性",
假设我知道项目节点所指的是什么.好吧,我右键单击并左键单击整个VS中的所有内容和任何内容,我找不到任何属性.也不是应该包含在构建中的文件.感觉就像是一个盲点或其中一个案例,也许那里有人可以帮助我?
问题
当我尝试在async方法中调用我的“ normal”方法时,它将从Debugger 1中被忽略。
这是我的异步方法
internal async static Task<DefinitionsModel> DeserializeAsync(this string path)
{
var model = new DefinitionsModel();
var content = await File.ReadAllTextAsync(path);
model.Pages = content.GetPages();
return model;
}
Run Code Online (Sandbox Code Playgroud)
这是我的“正常”方法
private static IEnumerable<PageModel> GetPages(this string content)
{
var level = 0;
var value = nameof(PageModel.Page).GetDElement<PageModel>();
var start_with_line = $"{level} {value} ";
var end_with_line = string.Concat(Enumerable.Repeat(Environment.NewLine, 2));
var expression = $@"\b{start_with_line}\S * {end_with_line}\b";
var matches = content.GetPagesFromContent(expression);
yield return new PageModel();
}
Run Code Online (Sandbox Code Playgroud)
帮助图片
c# ×10
.net ×2
c#-4.0 ×1
ienumerable ×1
json ×1
reflection ×1
replace ×1
string ×1
syntax-error ×1
timespan ×1
yield ×1