Created
May 30, 2016 10:39
-
-
Save abjerner/0bc1a0fcd542c16ef5af22cbf3a33168 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web; | |
public class StringWrapper { | |
public string Value { get; set; } | |
public HtmlString ValueAsHtml { | |
get { return new HtmlString(Value ?? ""); } | |
} | |
public bool IsEmpty { | |
get { return Value == ""; } | |
} | |
public bool IsNullOrEmpty { | |
get { return String.IsNullOrEmpty(Value); } | |
} | |
public bool IsNullOrWhiteSpace { | |
get { return String.IsNullOrWhiteSpace(Value); } | |
} | |
public bool IsNotNullOrWhiteSpace { | |
get { return !String.IsNullOrWhiteSpace(Value); } | |
} | |
public bool HasValue { | |
get { return !String.IsNullOrWhiteSpace(Value); } | |
} | |
public int Length { | |
get { return Value == null ? 0 : Value.Length; } | |
} | |
public StringWrapper() { | |
// Default constructor | |
} | |
public StringWrapper(string value) { | |
Value = value; | |
} | |
public override string ToString() { | |
return Value; | |
} | |
public HtmlString ToHtmlString() { | |
return new HtmlString(Value ?? ""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment