I have a class with about 10 or more different boolean values that record whether a user has done a particular action that will give them a specific reward (e.g. send a message to someone).
here is the code for one method for ONE bool/action:
private ReqRewardResult setMsgSent(RewardClass reward, RewardInfo info)
{
if (reward.msgSent)
return ReqRewardResult.RewardAlreadyGiven;
reward.msgSent = true;
reward.earned += info.msgSentReward;
return ReqRewardResult.ReqSuccess;
}
I have tried to create a generic method for this but it seems you can't pass a class variable as a reference?
private ReqRewardResult setRewardAction(ref bool bAction, RewardClass reward, int reward)
{
if (bAction)
return ReqRewardResult.RewardAlreadyGiven;
bAction = true;
reward.earnedTokens += reward;
return ReqRewardResult.ReqSuccess;
}
I have then looked at a couple of methods such as using a delegate function... but this is then kinda pointless as i'd have to repeat several lines again...
I have also seen you could use Reflection... but this is really slow and as this is a web app i'd rather use more repeated code if it improves the overall speed...
The question: Is there anyway to have a class function that can repeat for several variables of the same type without any performance hit?
NOTE: This class is data that is loaded from a database and is unique to each user (there could be millions of users)
Many Thanks,
Phil.