Esempio n. 1
0
        /// <summary>
        /// Tries to read element from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>True if element was read.</returns>
        internal override bool TryReadElementFromXml(EwsServiceXmlReader reader)
        {
            switch (reader.LocalName)
            {
            case XmlElementNames.ExtendedFieldURI:
                this.propertyDefinition = new ExtendedPropertyDefinition();
                this.propertyDefinition.LoadFromXml(reader);
                return(true);

            case XmlElementNames.Value:
                EwsUtilities.Assert(
                    this.PropertyDefinition != null,
                    "ExtendedProperty.TryReadElementFromXml",
                    "PropertyDefintion is missing");

                string stringValue = reader.ReadElementValue();
                this.value = MapiTypeConverter.ConvertToValue(this.PropertyDefinition.MapiType, stringValue);
                return(true);

            case XmlElementNames.Values:
                EwsUtilities.Assert(
                    this.PropertyDefinition != null,
                    "ExtendedProperty.TryReadElementFromXml",
                    "PropertyDefintion is missing");

                StringList stringList = new StringList(XmlElementNames.Value);
                stringList.LoadFromXml(reader, reader.LocalName);
                this.value = MapiTypeConverter.ConvertToValue(this.PropertyDefinition.MapiType, stringList);
                return(true);

            default:
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="jsonProperty">The json property.</param>
        /// <param name="service">The service.</param>
        internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service)
        {
            foreach (string key in jsonProperty.Keys)
            {
                switch (key)
                {
                case XmlElementNames.ExtendedFieldURI:
                    this.propertyDefinition = new ExtendedPropertyDefinition();
                    this.propertyDefinition.LoadFromJson(jsonProperty.ReadAsJsonObject(key));
                    break;

                case XmlElementNames.Value:
                    EwsUtilities.Assert(
                        this.PropertyDefinition != null,
                        "ExtendedProperty.TryReadElementFromXml",
                        "PropertyDefintion is missing");

                    string stringValue = jsonProperty.ReadAsString(key);
                    this.value = MapiTypeConverter.ConvertToValue(this.PropertyDefinition.MapiType, stringValue);
                    break;

                case XmlElementNames.Values:
                    EwsUtilities.Assert(
                        this.PropertyDefinition != null,
                        "ExtendedProperty.TryReadElementFromXml",
                        "PropertyDefintion is missing");

                    StringList stringList = new StringList(XmlElementNames.Value);
                    ((IJsonCollectionDeserializer)stringList).CreateFromJsonCollection(jsonProperty.ReadAsArray(key), service);
                    this.value = MapiTypeConverter.ConvertToValue(this.PropertyDefinition.MapiType, stringList);
                    break;

                default:
                    break;
                }
            }
        }