Here is an example of what I was suggesting a few streams ago. To be clear, I'm not saying it's "better". Just the way I usually do it because "I" think it's easier to read and maintain. Let me know what you think.
Wil
Original:
static WeaponProperties GetWeaponProperties(WeaponDto weaponDto)
{
WeaponProperties result = WeaponProperties.None;
if (MathUtils.IsChecked(weaponDto.Ammo))
result |= WeaponProperties.Ammunition;
if (MathUtils.IsChecked(weaponDto.Finesse))
result |= WeaponProperties.Finesse;
if (MathUtils.IsChecked(weaponDto.Heavy))
result |= WeaponProperties.Heavy;
if (MathUtils.IsChecked(weaponDto.Light))
result |= WeaponProperties.Light;
if (MathUtils.IsChecked(weaponDto.Martial))
result |= WeaponProperties.Martial;
if (MathUtils.IsChecked(weaponDto.Melee))
result |= WeaponProperties.Melee;
if (MathUtils.IsChecked(weaponDto.Ranged))
result |= WeaponProperties.Ranged;
if (MathUtils.IsChecked(weaponDto.Reach))
result |= WeaponProperties.Reach;
if (MathUtils.IsChecked(weaponDto.Special))
result |= WeaponProperties.Special;
if (MathUtils.IsChecked(weaponDto.Thrown))
result |= WeaponProperties.Thrown;
if (MathUtils.IsChecked(weaponDto.TwoHanded))
result |= WeaponProperties.TwoHanded;
if (MathUtils.IsChecked(weaponDto.Versatile))
result |= WeaponProperties.Versatile;
return result;
}
You could make the IncludeIf method global and generic as well. There would need to be a modification since you have to "change" the enum to a number to "or" it in a generic method. I don't think the global approach is worth the expense though (you have to box/unbox or something similar - like use IConvertible).
Mark,
Here is an example of what I was suggesting a few streams ago. To be clear, I'm not saying it's "better". Just the way I usually do it because "I" think it's easier to read and maintain. Let me know what you think.
Wil
Original:
Alternate:
More Generic:
You could make the IncludeIf method global and generic as well. There would need to be a modification since you have to "change" the enum to a number to "or" it in a generic method. I don't think the global approach is worth the expense though (you have to box/unbox or something similar - like use IConvertible).