Skip to content

Instantly share code, notes, and snippets.

@Nyconing
Created December 12, 2019 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nyconing/7ff7199f6b611ce3d86f89907716beef to your computer and use it in GitHub Desktop.
Save Nyconing/7ff7199f6b611ce3d86f89907716beef to your computer and use it in GitHub Desktop.
[Serializable]
public struct SubTypeText {
private object myValue;
public SubTypeText(DBNull aDBNull) {
this.myValue = (object) aDBNull;
}
public SubTypeText(string newValue) {
this.myValue = (object) newValue;
}
public bool HasValue {
get { return this.myValue != DBNull.Value; }
}
public override string ToString() {
return this.myValue.ToString();
}
public static implicit operator SubTypeText(string newValue) {
return new SubTypeText(newValue);
}
public static implicit operator SubTypeText(DBNull aDBNull) {
return new SubTypeText(aDBNull);
}
public static implicit operator string(SubTypeText aDBType) {
return aDBType.myValue.ToString();
}
public override bool Equals(object obj) {
if (this.HasValue)
return this.myValue.ToString() == obj.ToString();
if (obj != null)
return obj == DBNull.Value;
return true;
}
public override int GetHashCode() {
return this.myValue.GetHashCode();
}
public static bool operator ==(SubTypeText aDBType, DBNull aDBNull) {
return aDBType.myValue == aDBNull;
}
public static bool operator !=(SubTypeText aDBType, DBNull aDBNull) {
return aDBType.myValue != aDBNull;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment