我试图访问用户发送到我正在开发的skype机器人的附件列表。
以下是我访问附件详情的方法,
public async Task<HttpResponseMessage> Post([FromBody]Activity message)
{
if (message.Attachments != null)
{
if (message.Attachments.Count > 0)
{
List<Attachment> attachmentList = message.Attachments.ToList();
foreach (var item in attachmentList)
{
var name = item.Name;
var content = item.Content;
}
}
}
}
但即使附件计数大于零,我也会因以下原因而无效,
var name = item.Name;
var content = item.Content;
我这样做了吗?
答案 0 :(得分:-2)
也许做这样的事......
List<Attachment> attachmentList = message?.Attachments?.Where(x => x != null)?.ToList() ?? new List<Attachment>();
希望始终将attachmentList设置为空列表或包含非空项的列表?