2011-10-14 2 views
0

개체로 변환해야하는 xaml 파일이 있습니다. 이전에이 작업을 수행 한 사람이 있습니까?XAML 파일을 개체로 변환하는 방법

+0

당신에게 [방법 - 투 - 직렬화 일부 통찰력을 줄 수 있습니다 [1] [1] : http://stackoverflow.com/questions/364253/how-to- deserialize-xml-document –

+0

"개체로 변환"을 정의해야 할 일에 약간의 세부 사항을 추가해야합니다. 정밀도는 당신의 친구입니다. –

답변

2
using (var stream = File.OpenRead(filename)) { 
    var yourObj = XamlReader.Load(stream); 
} 
0
//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"); 
관련 문제