Skip to content

Instantly share code, notes, and snippets.

@abjerner
Created May 30, 2016 10:39
Show Gist options
  • Save abjerner/0bc1a0fcd542c16ef5af22cbf3a33168 to your computer and use it in GitHub Desktop.
Save abjerner/0bc1a0fcd542c16ef5af22cbf3a33168 to your computer and use it in GitHub Desktop.
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