Skip to content

Instantly share code, notes, and snippets.

@arphox
arphox / InternalHasFlag.cpp
Last active November 22, 2021 06:22
InternalHasFlag C++ implementation
// preform (this & flags) != flags
FCIMPL2(FC_BOOL_RET, ReflectionEnum::InternalHasFlag, Object *pRefThis, Object* pRefFlags)
{
FCALL_CONTRACT;
VALIDATEOBJECT(pRefThis);
BOOL cmp = false;
_ASSERTE(pRefFlags != NULL); // Enum.cs would have thrown ArgumentNullException before calling into InternalHasFlag
@arphox
arphox / Enum.HasFlag.cs
Last active November 22, 2021 06:22
Enum.HasFlag implementation
[System.Security.SecuritySafeCritical]
public Boolean HasFlag(Enum flag) {
if (flag == null)
throw new ArgumentNullException("flag");
Contract.EndContractBlock();
if (!this.GetType().IsEquivalentTo(flag.GetType())) {
throw new ArgumentException(Environment.GetResourceString("Argument_EnumTypeDoesNotMatch", flag.GetType(), this.GetType()));
}