C# 在对象中保存foreach属性
我正在尝试这样做:C# 在对象中保存foreach属性,c#,wpf,xaml,C#,Wpf,Xaml,我正在尝试这样做: private List<ICards> selectedCards = new List<ICards>(); foreach (var card in selectedCards) foreach (var item in card.GetType().GetProperties()) { string save =
private List<ICards> selectedCards = new List<ICards>();
foreach (var card in selectedCards)
foreach (var item in card.GetType().GetProperties())
{
string save = XamlWriter.Save(item);
tw.WriteLine(item.GetValue(card, null));
}
tw.Close();
}
例如:
class CardBizonOc : ICards
{
public string CardType { get; set; }
public string Name { get; set; }
public int AddressIndex { get; set; }
public string Entry1 { get; set; }
public string Entry2 { get; set; }
}
此时string save=XamlWriter.save(项目)代码>抛出:无法序列化类型“System.Reflection.RuntimePropertyInfo”。
我应该如何从卡中提取对象才能做到这一点?您不应该使用它吗?不,OP在序列化PropertyInfo类时有问题。这一系列化的目标是什么?是否将CardBizonOc的文本表示形式写入xaml文件?还是序列化所选卡片中每个元素的值?感谢您的回复,我在Nawed Nabi Zada的链接中找到了解决方案。现在它开始工作了。
class CardBizonOc : ICards
{
public string CardType { get; set; }
public string Name { get; set; }
public int AddressIndex { get; set; }
public string Entry1 { get; set; }
public string Entry2 { get; set; }