Example #1
0
        /// <summary>
        /// Alternative methods.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="json"></param>
        /// <returns></returns>

        public static string ConvertToString2(dynamic model, bool json = true /* else xml */)
        {
            string result;

            if (json)
            {
                result = JsonConvert.SerializeObject(model, Newtonsoft.Json.Formatting.Indented);
            }
            else
            {
                result = XmlToolkit.Serialize2(model);
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Convert data string to object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        /// <param name="json"></param>
        /// <returns></returns>
        public static T ConvertToModel <T>(string data, bool json = true /* else xml */)
        {
            T model;

            if (json)
            {
                model = JsonConvert.DeserializeObject <T>(data);
            }
            else
            {
                model = XmlToolkit.Deserialize <T>(data);
            }

            return(model);
        }
Example #3
0
        public static dynamic ConvertToModel2(string data, bool json = true /* else xml */)
        {
            dynamic model;

            if (json)
            {
                model = JsonConvert.DeserializeObject(data);
            }
            else
            {
                model = XmlToolkit.Deserialize2(data);
            }

            return(model);
        }