开发者

How to convert XAML File to objects

开发者 https://www.devze.com 2023-04-13 02:31 出处:网络
I开发者_如何学Python have a xaml file that needs to convert into objects, Is there anyone done this before?using (var stream = File.OpenRead(filename)) {

I开发者_如何学Python have a xaml file that needs to convert into objects, Is there anyone done this before?


using (var stream = File.OpenRead(filename)) {
    var yourObj = XamlReader.Load(stream);
}


//Configuration Class

namespace SKAT.Postfordeler.Shared.DataTypes
{
    [Serializable]
    public class PostFordelerConfiguration
    {

    private readonly ReceiverAddressList _receiverAddresses;
    private readonly DocumentTypeList _documentTypes;

    public PostFordelerConfiguration()
        {
            _receiverAddresses = new ReceiverAddressList();// I don't want to implement like this.
            _documentTypes = new DocumentTypeList(); //// I don't want to implement like this.
        }


    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ReceiverAddressList ReceiverAddresses
        {
            get { return _receiverAddresses; }
        }

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public DocumentTypeList DocumentTypes { get {return _documentTypes;} }


    public static PostFordelerConfiguration Load(string location)
        {
            return (PostFordelerConfiguration)XamlReader.Load(new XmlTextReader(location));
        }

   }
}

//Document Entity

namespace SKAT.Postfordeler.Shared.DataTypes
{
   [Serializable]
   public class DocumentType
    {
       public String Id { get; set; }
    }
}

//Document List

namespace SKAT.Postfordeler.Shared.DataTypes
{
    [Serializable]
    public class DocumentTypeList : List<DocumentType>{ }
}


//ReceiverAddress Entities

namespace SKAT.Postfordeler.Shared.DataTypes
{
    [Serializable]
    public class ReceiverAddress
    {
        public String Id { get; set; }
        public String Routable { get; set; }
        public String Description { get; set; }

    }
}

//ReceiverAddress List

namespace SKAT.Postfordeler.Shared.DataTypes
{
    [Serializable]
    public class ReceiverAddressList : List<ReceiverAddress>{ }
}


// Load XAML file and Convert into objects


SKAT.Postfordeler.Shared.DataTypes.PostFordelerConfiguration loader =
                Postfordeler.Shared.DataTypes.PostFordelerConfiguration.Load(
                    @"D:\projects\skatpostfordeler\SKAT.Postfordeler.Client.UI\PostfordelerConfiguration.xaml");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号