-
Notifications
You must be signed in to change notification settings - Fork 37
/
CustomFormatter.cs
154 lines (123 loc) · 4.45 KB
/
CustomFormatter.cs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//____________________________________________________________________________________________________________________________________
//
// Copyright (C) 2023, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community by pressing the `Watch` button and get started commenting using the discussion panel at
//
// https://github.com/mpostol/TP/discussions/182
//
// by introducing yourself and telling us what you do with this community.
//_____________________________________________________________________________________________________________________________________
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Linq;
namespace TP.DataStreams.Serialization
{
public class CustomFormatter : Formatter
{
#region IFormatter
public override void Serialize(Stream serializationStream, object graph)
{
ISerializable _data = (ISerializable)graph;
SerializationInfo _info = new SerializationInfo(graph.GetType(), new FormatterConverter());
StreamingContext _context = new StreamingContext(StreamingContextStates.File);
_data.GetObjectData(_info, _context);
foreach (SerializationEntry _item in _info)
this.WriteMember(_item.Name, _item.Value);
XmlWriter _writer = XmlWriter.Create(serializationStream);
XDocument m_xmlDocument = new XDocument(new XElement("SerializationTest", _values));
m_xmlDocument.Save(_writer);
_writer.Flush();
}
#region not implemented
public override object Deserialize(Stream serializationStream)
{
throw new NotImplementedException();
}
public override ISurrogateSelector SurrogateSelector { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override SerializationBinder Binder { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override StreamingContext Context { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
#endregion not implemented
#endregion IFormatter
#region private
private List<XElement> _values = new List<XElement>();
protected override void WriteDouble(double val, string name)
{
_values.Add(new XElement(name, val));
}
#region not implemented
protected override void WriteArray(object obj, string name, Type memberType)
{
throw new NotImplementedException();
}
protected override void WriteBoolean(bool val, string name)
{
throw new NotImplementedException();
}
protected override void WriteByte(byte val, string name)
{
throw new NotImplementedException();
}
protected override void WriteChar(char val, string name)
{
throw new NotImplementedException();
}
protected override void WriteDateTime(DateTime val, string name)
{
throw new NotImplementedException();
}
protected override void WriteDecimal(decimal val, string name)
{
throw new NotImplementedException();
}
protected override void WriteInt16(short val, string name)
{
throw new NotImplementedException();
}
protected override void WriteInt32(int val, string name)
{
throw new NotImplementedException();
}
protected override void WriteInt64(long val, string name)
{
throw new NotImplementedException();
}
protected override void WriteObjectRef(object obj, string name, Type memberType)
{
throw new NotImplementedException();
}
protected override void WriteSByte(sbyte val, string name)
{
throw new NotImplementedException();
}
protected override void WriteSingle(float val, string name)
{
throw new NotImplementedException();
}
protected override void WriteTimeSpan(TimeSpan val, string name)
{
throw new NotImplementedException();
}
protected override void WriteUInt16(ushort val, string name)
{
throw new NotImplementedException();
}
protected override void WriteUInt32(uint val, string name)
{
throw new NotImplementedException();
}
protected override void WriteUInt64(ulong val, string name)
{
throw new NotImplementedException();
}
protected override void WriteValueType(object obj, string name, Type memberType)
{
throw new NotImplementedException();
}
#endregion not implemented
#endregion private
}
}