Safe String Operations Extension
public static class StringExtensions
{
public static bool IsNullOrEmpty(this string value)
{
return string.IsNullOrEmpty(value);
}
public static bool IsNotNullOrEmpty(this string value)
{
return !string.IsNullOrEmpty(value);
}
public static string ToSafeString(this object value)
{
return value?.ToString() ?? string.Empty;
}
public static string Truncate(this string value, int maxLength)
{
if (string.IsNullOrEmpty(value)) return string.Empty;
return value.Length <= maxLength ? value : value.Substring(0, maxLength);
}
}