Ejemplo n.º 1
0
        public override void WriteObject(XmlWriter writer, object graph)
        {
            MeasurementContract MeasurementContractField = ((MeasurementContract)(graph));

            if (WriteParentElement(writer, true, true, graph))
            {
                if (WriteChildElement(writer, "light", false, true, MeasurementContractField.light))
                {
                    writer.WriteString(XmlConvert.ToString(MeasurementContractField.light));
                    writer.WriteEndElement();
                }
                if (WriteChildElement(writer, "moisture", false, true, MeasurementContractField.moisture))
                {
                    writer.WriteString(XmlConvert.ToString(MeasurementContractField.moisture));
                    writer.WriteEndElement();
                }
                if (WriteChildElement(writer, "temperature", false, true, MeasurementContractField.temperature))
                {
                    writer.WriteString(XmlConvert.ToString(MeasurementContractField.temperature));
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
            return;
        }
Ejemplo n.º 2
0
        public override object ReadObject(XmlReader reader)
        {
            MeasurementContract MeasurementContractField = null;

            if (IsParentStartElement(reader, false, true))
            {
                MeasurementContractField = new MeasurementContract();
                reader.Read();
                if (IsChildStartElement(reader, "light", false, true))
                {
                    reader.Read();
                    MeasurementContractField.light = XmlConvert.ToDouble(reader.ReadString());
                    reader.ReadEndElement();
                }
                if (IsChildStartElement(reader, "moisture", false, true))
                {
                    reader.Read();
                    MeasurementContractField.moisture = XmlConvert.ToInt32(reader.ReadString());
                    reader.ReadEndElement();
                }
                if (IsChildStartElement(reader, "temperature", false, true))
                {
                    reader.Read();
                    MeasurementContractField.temperature = XmlConvert.ToDouble(reader.ReadString());
                    reader.ReadEndElement();
                }
                reader.ReadEndElement();
            }
            return(MeasurementContractField);
        }