我试图找到一种方法来循环遍历一个对象以获取对象的所有属性(它们的名称和它们的值)。我可以成功地遍历简单的属性(例如字符串、整数等...,但是当它有一个包含属性的属性时——这就是问题所在......
[ Working for Simple string/int/bool properties ], but I need something that will work with nested / complex property types.
foreach (PropertyInfo spotProperties in spot.GetType().GetProperties())
{
// Simple property type (string, int, etc...) add the property and its value to the node.
var attributeName = spotProperties.Name;
resultElement.Add(new XElement(attributeName, spotProperties.GetValue(spot, null)));
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试完成但无法开始工作的示例代码 // 无法通过复杂的属性类型循环工作。
foreach (PropertyInfo spotProperties in spot.GetType().GetProperties())
{
if (--spotProperties is complex type then --)
{
// The item is a complex data type, and needs to …Run Code Online (Sandbox Code Playgroud) 我正在学习更多关于 JavaScript 承诺的知识,并在尝试将一些来自不同函数的承诺逻辑组合成一个内联函数时遇到了一个问题。当我将它全部放入一个内联函数中时,它会导致 promise 返回结果为“未定义”,而不是预期的“世界”值。
[按预期工作,它异步解决承诺,并导致承诺响应的“世界”]
app.get('/asyncTest', (request, response) => {
console.log("Request started...");
var helloResult = hello()
.then((res)=> {
console.log('COMPLETED Promise Result (Promise completed): ' + res)
});
console.log('Hello Result (immediately after issuing the promise [still in promise object format]): ' + helloResult);
console.log('Mesage at the end of the request (Should fire before completion of the promise result being fulfilled...');
});
function wait(ms) {
return new Promise(r => setTimeout(r, ms));
}
async function hello() {
await wait(3000);
return 'world';
} …Run Code Online (Sandbox Code Playgroud)