- -, , ( , ), . , , . , / , .
public struct Group
{
#region Code that is to be configured
public static readonly Group Alpha = new Group("Group Alpha");
public static readonly Group Beta = new Group("Group Beta");
public static readonly Group Invalid = new Group("N/A");
public static IEnumerable<Group> AllGroups
{
get
{
yield return Alpha;
yield return Beta;
yield return Invalid;
}
}
#endregion
private string value;
private Group(string value)
{
this.value = value;
}
public override bool Equals(object obj)
{
if (obj is Group)
{
return this.value.Equals(((Group)obj).value);
}
string otherString = obj as string;
if (otherString != null)
{
return this.value.Equals(otherString);
}
throw new ArgumentException("obj is neither a Group nor a String");
}
public override int GetHashCode()
{
return value.GetHashCode();
}
public static implicit operator string(Group group)
{
return group.value;
}
public static Group Parse(string input)
{
return AllGroups.Where(item => item.value == input).FirstOrDefault();
}
public static explicit operator Group(string other)
{
return Parse(other);
}
public override string ToString()
{
return value;
}
}