Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在对象中保存foreach属性_C#_Wpf_Xaml - Fatal编程技术网

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; }