Example #1
0
        /// <summary>
        /// Saves a property value to the database.
        /// </summary>
        /// <param name="property">The property to be saved</param>
        /// <param name="value">The value to save for the property (not null)</param>
        /// <exception cref="ArgumentNullException">The specified value is undefined.</exception>
        /// <remarks>Once added, you cannot delete it using this method.</remarks>
        void SaveProperty(PropertyNaming property, string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            string propertyName = property.ToString();
            string sql;

            // TODO: may want to escape chars in the value

            if (Database.IsExisting(PropertiesTableName, $"Name='{propertyName}'"))
            {
                sql = $"UPDATE {PropertiesTableName} " +
                      $"SET Value='{value}' " +
                      $"WHERE Name='{propertyName}'";
            }
            else
            {
                sql = $"INSERT INTO {PropertiesTableName} (Name,Value) " +
                      $"VALUES ('{propertyName}', '{value}')";
            }

            int nRows = Database.ExecuteNonQuery(sql);

            Debug.Assert(nRows == 1);
        }
Example #2
0
        public static string ToJson(this object data, PropertyNaming propertyNaming = PropertyNaming.Default)
        {
            if (data == null)
            {
                return null;
            }

            var settings = new JsonSerializerSettings();

            if (propertyNaming == PropertyNaming.CamelCase)
            {
                settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            }

            settings.Converters.Add(new StringEnumConverter());

            return JsonConvert.SerializeObject(data, settings);
        }
Example #3
0
        public static string ToJson(this object data, PropertyNaming propertyNaming = PropertyNaming.Default)
        {
            if (data == null)
            {
                return(null);
            }

            var settings = new JsonSerializerSettings();

            if (propertyNaming == PropertyNaming.CamelCase)
            {
                settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            }

            settings.Converters.Add(new StringEnumConverter());

            return(JsonConvert.SerializeObject(data, settings));
        }