Exemplo n.º 1
0
 /// <summary>
 /// Populates the object from the supplied JSON
 /// </summary>
 /// <param name="JSON">The JSON string representing the WTTHeader object</param>
 private void PopulateFromJSON(string JSON)
 {
     //JSON argument will already have been validated in the constructor
     try
     {
         WTTActivityCollection Temp = JsonConvert.DeserializeObject <WTTActivityCollection>(JSON, new WTTActivityCollectionConverter());
         this._Activities = Temp.ToList();
     }
     catch (Exception Ex)
     {
         throw new ApplicationException(ExceptionHelper.GetStaticException("ParseWTTActivityCollectionJSONError", null, Globals.UserSettings.GetCultureInfo()), Ex);
     }
 }
        /// <summary>
        /// Override method to serialize a WTTActivityCollection object to a JSON string
        /// </summary>
        /// <returns></returns>
        public override void WriteJson(JsonWriter Writer, object Value, JsonSerializer Serializer)
        {
            //Validate Arguments
            if (Serializer == null)
            {
                throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Serializer" }, new System.Globalization.CultureInfo("en-GB")));
            }

            if (Writer == null)
            {
                throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Writer" }, new System.Globalization.CultureInfo("en-GB")));
            }

            if (Value == null)
            {
                throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Value" }, new System.Globalization.CultureInfo("en-GB")));
            }

            WTTActivityCollection ActivityCollection = (WTTActivityCollection)Value;

            // create the surrogate and serialize it instead
            // of the collection itself
            Serializer.Serialize(Writer, ActivityCollection.ToWTTActivityCollectionSurrogate());
        }