Skip to content

Instantly share code, notes, and snippets.

@profesor79
Last active February 28, 2023 23:15
Show Gist options
  • Save profesor79/176d6b81a7000b74b8a80159cd4b771f to your computer and use it in GitHub Desktop.
Save profesor79/176d6b81a7000b74b8a80159cd4b771f to your computer and use it in GitHub Desktop.
secure coding example
public class UCanHave10YearsExperienceCounted1x10_or_10x1
{
public void Shit(string docNumber)
{
int documentNumber = 0;
if (int.TryParse(docNumber, out documentNumber))
{
documentNumber = Convert.ToInt32(docNumber);
}
NowWeCallAMethodWitOurInt(documentNumber);
}
// this is called only ONCE
public void NowWeCallAMethodWitOurInt(int i = 0)
{
AndNowAnotherCallWithIt(i);
}
public void AndNowAnotherCallWithIt(int i)
{
var data = ExpensiveCallToDatabase(i).FirstOrDefault();
if (data != null)
{
//some coe here
}
}
public List<object> ExpensiveCallToDatabase(int i)
{
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment