public static bool EqualsIgnoreCase(this Fixable <string> s1, string s2) => ReferenceEquals(s1.Value, s2) || true == s1.Value?.Equals(s2, StringComparison.OrdinalIgnoreCase);
public static bool Equals(this Fixable <string> s1, string s2, StringComparison comparison) => ReferenceEquals(s1.Value, s2) || s1.Value.Equals(s2, comparison);
public static bool Equals(this string s1, Fixable <string> s2, StringComparison comparison) => ReferenceEquals(s1, s2.Value) || s1.Equals(s2.Value, comparison);
public static string ToPascalCase(this Fixable <string> value) => CodeNamer.Instance.PascalCase(value.Value);
public static string EscapeXmlComment(this Fixable <string> comment) => EscapeXmlComment(comment.Value);
public static string Substring(this Fixable <string> str, int startIndex) => str.Value.Substring(startIndex);
/// <summary> /// Overriden to suppress serialization of IEnumerables that are empty. /// </summary> /// <param name="member"></param> /// <param name="memberSerialization"></param> /// <returns></returns> protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var property = base.CreateProperty(member, memberSerialization); if (typeof(IModelType).IsAssignableFrom(property.PropertyType) || property.PropertyType.IsGenericOf(typeof(IEnumerableWithIndex <>))) { property.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; property.IsReference = true; } // if the property is marked as a JsonObject, it should never be treated as a collection // and hence, doesn't need our ShouldSerialize overload. if (property.PropertyType.CustomAttributes.Any(each => each.AttributeType == typeof(JsonObjectAttribute))) { return(property); } if (property.PropertyType.IsConstructedGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Fixable <>)) { // gotta stick this in here for a bit. property.ShouldDeserialize = property.ShouldSerialize = instance => { Fixable f = null; var m = instance.GetType().GetMember(member.Name)[0]; if (m is PropertyInfo) { f = instance .GetType() .GetProperty(member.Name) .GetValue(instance, null) as Fixable; } else { f = instance .GetType() .GetField(member.Name) .GetValue(instance) as Fixable; } if (f == null) { return(false); } return(f.ShouldSerialize && !f.IsFixed); }; property.ShouldSerialize = instance => { Fixable f = null; var m = instance.GetType().GetMember(member.Name)[0]; if (m is PropertyInfo) { f = instance .GetType() .GetProperty(member.Name) .GetValue(instance, null) as Fixable; } else { f = instance .GetType() .GetField(member.Name) .GetValue(instance) as Fixable; } if (f == null) { return(false); } return(f.ShouldSerialize && f.IsFixed); }; } // if the property is an IEnumerable, put a ShouldSerialize delegate on it to check if it's empty before we bother serializing if ((property.PropertyType != typeof(string)) && typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) { property.ShouldSerialize = instance => { IEnumerable enumerable = null; // this value could be in a public field or public property switch (member.MemberType) { case MemberTypes.Property: enumerable = instance .GetType() .GetProperty(member.Name) .GetValue(instance, null) as IEnumerable; break; case MemberTypes.Field: enumerable = instance .GetType() .GetField(member.Name) .GetValue(instance) as IEnumerable; break; } return((enumerable == null) || enumerable.GetEnumerator().MoveNext()); }; } return(property); }
public static bool StartsWithIgnoreCase(this Fixable <string> str, string startsWith) => true == str?.Value?.StartsWith(startsWith, StringComparison.OrdinalIgnoreCase);
public static string EnsureEndsWith(this Fixable <string> str, string suffix) => str.IsNullOrEmpty() ? str.Value : str.Value.EnsureEndsWith(suffix);
public static int IndexOf(this Fixable <string> str, char chr) => str?.Value?.IndexOf(chr) ?? -1;
public static int IndexOfIgnoreCase(this Fixable <string> str, string text) => str?.Value?.IndexOf(text, StringComparison.OrdinalIgnoreCase) ?? -1;
public static bool Contains(this Fixable <string> str, char chr) => true == str?.Value?.Contains(chr);
public static bool Contains(this Fixable <string> str, string contained) => true == str?.Value?.Contains(contained);
public static bool IsNullOrEmpty(this Fixable <string> str) => string.IsNullOrWhiteSpace(str?.Value);
public static bool EqualsIgnoreCase(this Fixable <string> s1, Fixable <string> s2) => ReferenceEquals(s1.Value, s2.Value) || s1.Value.Equals(s2.Value, StringComparison.OrdinalIgnoreCase);
public static string Else(this Fixable <string> preferred, Fixable <string> fallback) => string.IsNullOrWhiteSpace(preferred.Value) ? fallback.Value : preferred.Value;
public static char CharAt(this Fixable <string> str, int index) => str.Value[index];
public static string TrimEnd(this Fixable <string> str, char ch) => str.Value.TrimEnd(ch);
public static string ToLower(this Fixable <string> str) => str?.Value.ToLowerInvariant();
public static void Null(Fixable<string> str) { Assert.Null(str.Value); }