Why don't use an enum?
[Flags]
public enum PersonState
{
None = 0,
Archived = 1,
Deleted = 2,
Both = Archived | Deleted
}
class Person
{
private PersonState status;
public PersonState Status
{
get { return this.status; }
set { this.status = value; }
}
public bool IsArchived
{
get
{
return (this.status & PersonState.Archived) != 0;
}
set
{
if (value)
this.status |= PersonState.Archived;
else
this.status &= ~PersonState.Archived;
}
}
public bool IsDeleted
{
get
{
return (this.status & PersonState.Deleted) != 0;
}
set
{
if (value)
this.status |= PersonState.Deleted;
else
this.status &= ~PersonState.Deleted;
}
}
}
You can directly cast an enum value to integer.
int x = (int)person.Status;
And you can do the contrary, if you have an int.
person.Status = (PersonState)integerValue;
Also if you don't provide the possibility that Deleted and Archived can coexists together this is actually a possibility with booleans.
The number of possible values encoded by n boolean values is 2^n, so, since you have 2 booleans, you have 4 possible values, 00, 01, 10 and 11.
The problem is in the problem itself: it is wrong to encode that information with booleans. It should be an enum with only 3 possible values also in the DB.