【发布时间】:2021-04-03 11:32:30
【问题描述】:
我有一段代码通过库检索一长串成员。
public List<InstinctGuildMember> PrepareGuildMembersList()
{
List<GuildMember> warcraftGuildMembers = _warcraftClient.GetGuildRosterAsync("dragonmaw", "instinct", "profile-eu")
.Result.Value.Members.OrderBy(members => members.Rank)
.ThenBy(members => members.Character.Name)
.ToList();
// We cast a new List from our old List.
List<InstinctGuildMember> instinctGuildMembers = new List<InstinctGuildMember>(warcraftGuildMembers.Cast<InstinctGuildMember>());
return instinctGuildMembers;
}
namespace guild_instinct.Models.GuildData
{
public class InstinctGuildMember : GuildMember
{
public string RankName { get; set; }
}
}
我想转换为我自己的模型的原因是因为提供的模型没有我需要的所有信息。我的一个朋友建议制作我自己的模型并从库中继承模型。
我在related StackOverflow question 上找到了这个解决方案。但是,我无法让它工作,因为我一直收到错误后的错误
System.InvalidCastException: '无法将'ArgentPonyWarcraftClient.GuildMember'类型的对象转换为'guild_instinct.Models.GuildData.InstinctGuildMember'类型。'
到目前为止,我可能只是缺乏正确做这件事的知识,而答案就在眼前。
我不知道如何继续。我应该深入研究哪些知识来进一步进步?我的方向是否正确,但我是否缺乏使其发挥作用的一些基础知识?我希望我的问题足够简洁,值得帮助。
【问题讨论】:
标签: c# list model-view-controller model