/// <summary>
        /// Serializes the property to a Json value.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <returns>
        /// A Json value (either a JsonObject, an array of Json values, or a Json primitive)
        /// </returns>
        internal override object InternalToJson(ExchangeService service)
        {
            JsonObject jsonExtendedProp = new JsonObject();

            JsonObject jsonExtendedFieldUri = new JsonObject();

            this.PropertyDefinition.AddJsonProperties(jsonExtendedFieldUri, service);

            jsonExtendedProp.Add(XmlElementNames.ExtendedFieldURI, jsonExtendedFieldUri);

            if (MapiTypeConverter.IsArrayType(this.PropertyDefinition.MapiType))
            {
                List <object> values = new List <object>();

                foreach (object value in this.Value as Array)
                {
                    values.Add(MapiTypeConverter.ConvertToString(this.PropertyDefinition.MapiType, value));
                }

                jsonExtendedProp.Add(XmlElementNames.Values, values.ToArray());
            }
            else
            {
                jsonExtendedProp.Add(
                    XmlElementNames.Value,
                    MapiTypeConverter.ConvertToString(this.PropertyDefinition.MapiType, this.Value));
            }

            return(jsonExtendedProp);
        }
        /// <summary>
        /// Gets the string value.
        /// </summary>
        /// <returns>Value as string.</returns>
        private string GetStringValue()
        {
            if (MapiTypeConverter.IsArrayType(this.PropertyDefinition.MapiType))
            {
                Array array = this.Value as Array;
                if (array == null)
                {
                    return(string.Empty);
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("[");
                    for (int index = array.GetLowerBound(0); index <= array.GetUpperBound(0); index++)
                    {
                        sb.Append(
                            MapiTypeConverter.ConvertToString(
                                this.PropertyDefinition.MapiType,
                                array.GetValue(index)));
                        sb.Append(",");
                    }
                    sb.Append("]");

                    return(sb.ToString());
                }
            }
            else
            {
                return(MapiTypeConverter.ConvertToString(this.PropertyDefinition.MapiType, this.Value));
            }
        }
        /// <summary>
        /// Writes elements to XML.
        /// </summary>
        /// <param name="writer">The writer.</param>
        internal override void WriteElementsToXml(EwsServiceXmlWriter writer)
        {
            this.PropertyDefinition.WriteToXml(writer);

            if (MapiTypeConverter.IsArrayType(this.PropertyDefinition.MapiType))
            {
                Array array = this.Value as Array;
                writer.WriteStartElement(XmlNamespace.Types, XmlElementNames.Values);
                for (int index = array.GetLowerBound(0); index <= array.GetUpperBound(0); index++)
                {
                    writer.WriteElementValue(
                        XmlNamespace.Types,
                        XmlElementNames.Value,
                        MapiTypeConverter.ConvertToString(this.PropertyDefinition.MapiType, array.GetValue(index)));
                }
                writer.WriteEndElement();
            }
            else
            {
                writer.WriteElementValue(
                    XmlNamespace.Types,
                    XmlElementNames.Value,
                    MapiTypeConverter.ConvertToString(this.PropertyDefinition.MapiType, this.Value));
            }
        }