diff options
author | Lluis Sanchez <lluis@novell.com> | 2003-09-01 18:13:23 +0400 |
---|---|---|
committer | Lluis Sanchez <lluis@novell.com> | 2003-09-01 18:13:23 +0400 |
commit | 1f9698d02a0b8e2646d617f7b767c5f18b99dacc (patch) | |
tree | 79ec8aa465df6f463f87428bd0abec5b952153b3 /mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs | |
parent | e2f81e3c338fb8720ab74e5ed2780102ebbb85ef (diff) |
* XmlSchemaImporter.cs: Implemented ImportMembersMapping.
* XmlTypeMapMemberElement.cs: Little fix.
* XmlTypeMapping.cs: Added AllElementInfos property in ClassMap.
* XmlCustomFormatter.cs: Added GenerateToXmlString and GenerateFromXmlString
methods.
* SerializationCodeGenerator.cs, SerializationCodeGeneratorConfiguration.cs:
Added.
svn path=/trunk/mcs/; revision=17792
Diffstat (limited to 'mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs')
-rw-r--r-- | mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs index dbf04d5d913..096a7501a94 100644 --- a/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs @@ -207,6 +207,59 @@ namespace System.Xml.Serialization { } } + internal static string GenerateToXmlString (TypeData type, string value) + { + switch (type.XmlType) + { + case "boolean": return "(" + value + "?\"true\":\"false\")"; + case "unsignedByte": return value + ".ToString()"; + case "char": return value + ".ToString()"; + case "dateTime": return value + ".ToString(\"yyyy-MM-ddTHH:mm:ss.fffffffzzz\", CultureInfo.InvariantCulture)"; + case "date": return value + ".ToString(\"yyyy-MM-dd\", CultureInfo.InvariantCulture)"; + case "time": return value + ".ToString(\"HH:mm:ss.fffffffzzz\", CultureInfo.InvariantCulture"; + case "decimal": return "XmlConvert.ToString (" + value + ")"; + case "double": return "XmlConvert.ToString (" + value + ")"; + case "short": return value + ".ToString()"; + case "int": return value + ".ToString()"; + case "long": return value + ".ToString()"; + case "byte": return value + ".ToString()"; + case "float": return "XmlConvert.ToString (" + value + ")"; + case "unsignedShort": return value + ".ToString()"; + case "unsignedInt": return value + ".ToString()"; + case "unsignedLong": return value + ".ToString()"; + case "guid": return "XmlConvert.ToString (" + value + ")"; + case "base64Binary": return "Convert.ToBase64String (" + value + ")"; + case "string": return value; + default: return value + ".ToString()"; + } + } + + internal static string GenerateFromXmlString (TypeData type, string value) + { + switch (type.XmlType) + { + case "boolean": return "XmlConvert.ToBoolean (" + value + ")"; + case "unsignedByte": return "SByte.Parse(" + value + ")"; + case "char": return "(char)Int32.Parse (" + value + ")"; + case "dateTime": return "XmlConvert.ToDateTime (" + value + ")"; + case "date": return "DateTime.ParseExact (" + value + ", \"yyyy-MM-dd\", null)"; + case "time": return "DateTime.ParseExact (" + value + ", \"HH:mm:ss.fffffffzzz\", null)"; + case "decimal": return "Decimal.Parse (" + value + ")"; + case "double": return "XmlConvert.ToDouble (" + value + ")"; + case "short": return "Int16.Parse (" + value + ")"; + case "int": return "Int32.Parse (" + value + ")"; + case "long": return "Int64.Parse (" + value + ")"; + case "byte": return "SByte.Parse (" + value + ")"; + case "float": return "XmlConvert.ToSingle (" + value + ")"; + case "unsignedShort": return "UInt16.Parse (" + value + ")"; + case "unsignedInt": return "UInt32.Parse (" + value + ")"; + case "unsignedLong": return "UInt64.Parse (" + value + ")"; + case "guid": return "XmlConvert.ToGuid (" + value + ")"; + case "base64Binary": return "Convert.FromBase64String (" + value + ")"; + default: return value; + } + } + #endregion // Methods } } |