/// <summary> /// Writes the JSON representation of the object. /// </summary> /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param> /// <param name="value">The value.</param> /// <param name="serializer">The calling serializer.</param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var text = value.SafeToString(); if (!string.IsNullOrWhiteSpace(text)) { switch (NamingRule) { case EnumStringNamingRule.BySlash: text = StringRegexExtension.SplitByUpperCases(text, "-"); break; case EnumStringNamingRule.LowerCamelCase: text = Convert.ToString(Char.ToLowerInvariant(text[0])) + (text.Length > 1 ? text.Substring(1) : string.Empty); break; case EnumStringNamingRule.LowerCases: text = text.ToLowerInvariant(); break; } } writer.WriteValue(string.IsNullOrWhiteSpace(text) ? null : text); }
/// <summary> /// Splits the sentence by upper cases. /// </summary> /// <param name="anyString">Any string.</param> /// <returns></returns> public static string SplitSentenceByUpperCases(this string anyString) { return(StringRegexExtension.SplitByUpperCases(anyString, StringConstants.WhiteSpace)); }