WOX2
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
|
using System;
using System.Reflection;
/// <header>
/// <wox>
/// <version>1.0</version>
/// <author>Carlos R. Jaimez Gonzalez</author>
/// <author>Simon M. Lucas</author>
/// <site>http://woxserializer.sourceforge.net/</site>
/// </wox>
/// <wox>
/// <version>1.5</version>
/// <author>Steven M Lewis</author>
/// </wox>
/// <wox>
/// <version>2.0</version>
/// <author>George A Smith</author>
/// <svn>http://woxserializer.sourceforge.net/</svn>
/// <note>XML form for vs 2 is more compact and therefor incompatible with vs 1</note>
/// </wox>
/// </header>
namespace wox.serial
{
public abstract class AbstractStringableHandler : AbstractHandler, WoxIsAHandler
{
#region WoxIsAHandler Members
public abstract bool IsFor( Type pType );
public override object ReadObject( WoxHandlers pWoxHandlers, WoxReader pWoxReader, XMLreader pReader )
{
try
{
string zValue = pReader.GetAttribute( Serial.VALUE );
return CreateInstance( zValue );
}
catch ( Exception e )
{
throw new ApplicationException( GetType().Name + " Exception is: " + e.Message, e );
}
}
public override void WriteObject( WoxHandlers pWoxHandlers, WoxWriter pWoxWriter, object pObject, FieldInfo pField, XMLwriter pWriter, bool pJustType )
{
pWriter.WriteStartElement( Serial.OBJECT );
string zValue = Stringify( pObject );
if ( zValue != null )
{
pWriter.WriteAttributeString( Serial.TYPE, GetWoxTypeFor( pWoxHandlers, pObject.GetType(), pField, pJustType ) );
pWriter.WriteAttributeString( Serial.VALUE, zValue );
}
pWriter.WriteEndElement();
}
public override object ParseFieldValue( string pFieldValue )
{
return CreateInstance( pFieldValue );
}
public override string CreateFieldValue( object pFieldValue )
{
return Stringify( pFieldValue );
}
#endregion
abstract protected object CreateInstance( string pValue );
protected virtual string Stringify( object pObject )
{
return (pObject == null) ? Serial.NULL : pObject.ToString();
}
}
}
|