-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSerializeToXml.cs
More file actions
65 lines (57 loc) · 2.27 KB
/
SerializeToXml.cs
File metadata and controls
65 lines (57 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using EdiFabric.Core.Model.Edi;
using EdiFabric.Examples.NCPDP.Telco.Common;
using EdiFabric.Framework.Readers;
using EdiFabric.Templates.TelcoD0;
namespace EdiFabric.Examples.NCPDP.Telco.XML
{
class SerializeToXml
{
/// <summary>
/// Serialize an NCPDP object to XML using XmlSerializer
/// </summary>
public static void WithXmlSerializer()
{
Debug.WriteLine("******************************");
Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
Debug.WriteLine("******************************");
var ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + Config.TestFilesPath + @"\ClaimBilling");
List<IEdiItem> ncpdpItems;
using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
{
ncpdpItems = ncpdpReader.ReadToEnd().ToList();
}
var transactions = ncpdpItems.OfType<TSB1>();
foreach (var transaction in transactions)
{
var xml = transaction.Serialize();
Debug.WriteLine(xml.Root.ToString());
}
}
/// <summary>
/// Serialize an NCPDP object to NCPDP using DataContractSerializer
/// </summary>
public static void WithDataContractSerializer()
{
Debug.WriteLine("******************************");
Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
Debug.WriteLine("******************************");
var ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + Config.TestFilesPath + @"\ClaimBilling");
List<IEdiItem> ncpdpItems;
using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
{
ncpdpItems = ncpdpReader.ReadToEnd().ToList();
}
var transactions = ncpdpItems.OfType<TSB1>();
foreach (var transaction in transactions)
{
var xml = transaction.SerializeDataContract();
Debug.WriteLine(xml.Root.ToString());
}
}
}
}