Skip to content

Instantly share code, notes, and snippets.

@ClysmiC
Created August 16, 2019 21:20
Show Gist options
  • Save ClysmiC/286d49670139df4e50494e4d2d4730e7 to your computer and use it in GitHub Desktop.
Save ClysmiC/286d49670139df4e50494e4d2d4730e7 to your computer and use it in GitHub Desktop.
Access modifier on optional parameter
public class SecureTransactor
{
public bool DoManySecureTransactions(string[] data)
{
if (!SecurityCheck()) return false;
bool doCheck = false; // We already did the check, no need to repeat ourselves!
foreach(string datum in data)
{
DoSecureTranaction(data, doCheck);
}
}
public bool DoSecureTransaction(string data, protected bool doSecurityCheck=true)
{
// Notice the protected default argument. Externally, this function can only be
// called with 1 argument. Internally, we can supply whatever value we choose
if (doSecurityChecks && !SecurityCheck())
{
return false;
}
// ...
return true;
}
protected bool SecurityCheck()
{
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment