I have a xaml file that needs to convert into objects, Is there anyone done this before?
Asked
Active
Viewed 468 times
0
-
May give you some insight [how-to-deserialize][1] [1]: http://stackoverflow.com/questions/364253/how-to-deserialize-xml-document – Romaine Carter Oct 14 '11 at 03:06
-
you should define "convert into objects" add some detail to what you need to do. precision is your friend. – Muad'Dib Oct 14 '11 at 03:09
2 Answers
2
using (var stream = File.OpenRead(filename)) {
var yourObj = XamlReader.Load(stream);
}

Amry
- 4,791
- 2
- 23
- 24
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");

user335160
- 1,364
- 6
- 32
- 67