The most obvious solution is to set an int value, call the method with a ref to that value, then reset it to the ambientState property, as follows:
public bool Morning {
get { ... }
set {
int as = (int)this.ambientState;
this.SetFlag(value, ref as, ...);
this.ambientState = (AmbientState)as;
}
}
Another solution I see is doing the reverse, which is probably better, since you cut down on the responsibility of the user, and to impede type checking for your enum type. Do this as follows:
protected bool SetFlag(bool _new, ref AmbientState _flags, AmbientState _flag, string _pName)
{
int flag = (int)_flag;
int flags = (int)_flags;
bool __cancelled = false;
bool __old = ((flags & flag) == flag);
if (!__old.Equals(_new)
{
if (!(__cancelled = this.RaisePropertyChanging(__old, _new, pName)))
{
flags = (_new) ? flags | flag : flags & ~flag;
this.RaisePropertyChanged(__old, _new, pName);
_flags = (AmbientState)flags;
}
}
return __cancelled;
}
And finally, the RECOMMENDED way of doing this, is setting the FlagsAttribute on the enumeration as follows:
[FlagsAttribute]
public enum AmbientState {
...
}
This final way allows you to use &, |, and ^ on the values of the enumeration. I'm not sure if you can use ~, but you can always go to find out! Hope this helps,
-Jeff