首页 > 解决方案 > XamlWriter.Save foreach 对象中的属性

问题描述

我正在做这样的事情:

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

ICards是接口的地方

interface ICards
{
    string CardType { get; set; }
    string Name { get; set; }
    int AddressIndex { get; set; }
}

和例子:

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(item);抛出:You cannot serialize the type "System.Reflection.RuntimePropertyInfo".

我应该如何将物体拉出来card才能做到?

标签: c#wpfxaml

解决方案


推荐阅读