コード例 #1
0
ファイル: XmlSerializer.cs プロジェクト: Rhesos/SDKGadgeteer
 private static void SerializeEnum(object instance, XmlWriter xmlWriter, FieldInfo fieldInfo)
 {
     // TODO: desktop .NET serializes enums with their .ToString() value ("Two") in the case below
     // NETMF does not have the ability to parse an enum and only serializes the base value (1) in the case below
 }
コード例 #2
0
ファイル: System.Xml.Ext.cs プロジェクト: awakegod/NETMF-LPC
        //
        // Summary:
        //     Creates a new System.Xml.XmlWriter instance using the specified stream.
        //
        // Parameters:
        //   output:
        //     The stream to which you want to write. The System.Xml.XmlWriter writes XML
        //     1.0 text syntax and appends it to the specified stream.
        //
        // Returns:
        //     An System.Xml.XmlWriter object.
        //
        // Exceptions:
        //   System.ArgumentNullException:
        //     The stream value is null.
        public static XmlWriter Create(Stream output)
        {
            if (output == null)
                throw new ArgumentNullException("output", "stream must not be null");

            XmlWriter writer = new XmlWriter(output);
            return writer;
        }
コード例 #3
0
ファイル: XmlSerializer.cs プロジェクト: Rhesos/SDKGadgeteer
        private static void SerializeArray(object instance, XmlWriter xmlWriter, FieldInfo fieldInfo)
        {
            object array = fieldInfo.GetValue(instance);
            string typeName = array.GetType().GetElementType().Name;

            switch (typeName)
            {
                case "Boolean":
                    typeName = "boolean";
                    break;

                case "Byte":
                    // TODO: this is not an array but a base64 encoded string but have not figured out how to decode it
                    //xmlWriter.WriteElementString(fieldInfo.Name, Convert.ToBase64String((byte[])array));
                    return;

                case "SByte":
                    typeName = "byte";
                    break;

                case "Char":
                    typeName = "char";
                    break;

                case "DateTime":
                    typeName = "dateTime";
                    break;

                case "Double":
                    typeName = "double";
                    break;

                case "Guid":
                    typeName = "guid";
                    break;

                case "Int16":
                    typeName = "short";
                    break;
                case "UInt16":
                    typeName = "unsignedShort";
                    break;

                case "Int32":
                    typeName = "int";
                    break;
                case "UInt32":
                    typeName = "unsignedInt";
                    break;

                case "Int64":
                    typeName = "long";
                    break;
                case "UInt64":
                    typeName = "unsignedLong";
                    break;

                case "Single":
                    typeName = "float";
                    break;

                case "String":
                    typeName = "string";
                    break;
            }

            xmlWriter.WriteStartElement(fieldInfo.Name);

            foreach (var item in (IEnumerable)array)
            {
                switch (typeName)
                {
                    case "boolean":
                        // these need to be lowercase
                        xmlWriter.WriteElementString(typeName, item.ToString().ToLower());
                        break;

                    case "char":
                        xmlWriter.WriteElementString(typeName, Encoding.UTF8.GetBytes(item.ToString())[0].ToString());
                        break;

                    case "dateTime":
                        xmlWriter.WriteElementString(typeName, ((DateTime)item).ToString("s"));
                        break;

                    default:
                        xmlWriter.WriteElementString(typeName, item.ToString());
                        break;
                }
            }

            xmlWriter.WriteEndElement();
        }