Ciao a tutti non so magari qualcuno lo ha già fatto, ma volevo condividerlo con voi queste funzioni c# (da inserire magari in una classe) che vi permettono di controllare i valori passati.
Codice PHP:
/* Controllo se il valore passato è un Decimal */
#region CheckDecimal
private bool cleanDecimal(string argValue)
{
bool isDecimal = false;
decimal Value;
try
{
Value = Convert.ToDecimal(argValue);
isDecimal = true;
}
catch
{
isDecimal = false;
}
return isDecimal;
}
#endregion
/* Controllo se il valore passato è una DataValida */
#region CheckDateTime
private bool cleanDateTime(string argValue)
{
bool isDataTime = false;
DateTime Value;
try
{
Value = Convert.ToDateTime(argValue);
isDataTime = true;
}
catch
{
isDataTime = false;
}
return isDataTime;
}
#endregion
/* Controllo se il valore passato è un Intero */
#region CheckInt
private bool cleanInt(string argValue)
{
bool isInt = false;
int Value;
try
{
Value = Convert.ToInt32(argValue);
isInt = true;
}
catch
{
isInt = false;
}
return isInt;
}
#endregion
/* Controllo se il valore passato è un Double */
#region CheckDouble
private bool cleanDouble(string argValue)
{
bool isDouble = false;
double Value;
try
{
Value = Convert.ToDouble(argValue);
isDouble = true;
}
catch
{
isDouble = false;
}
return isDouble;
}
#endregion
/* Controllo se il valore passato è un Bool */
#region CheckBool
private bool cleanBool(string argValue)
{
bool isBool = false;
bool Value;
try
{
Value = Convert.ToBoolean(argValue);
isBool = true;
}
catch
{
isBool = false;
}
return isBool;
}
#endregion
/* Ripulisco la Stringa da Carattere Strani */
#region CheckString
private string cleanString(string argValue)
{
string value;
value = argValue.Replace("'", "''");
value = argValue.Replace("drop", "");
value = argValue.Replace("insert", "");
value = argValue.Replace("update", "");
value = argValue.Replace("xp_", "");
return value;
}
#endregion
Alla prossima.

Rispondi quotando