i need a method to check the all class properties for null value and if just one of the properties is null then return false. something like this:
public static bool Check<T>(T instance)
{
foreach (var parameter in instance)
{
if (parameter == null)
return false;
}
return true;
}
how can i do it?
Update:
its not a duplicate question!!!. i already saw this link and the different is my class properties has different types (string
, int
, double
....). so i need a method to check them out to. here is one of my classes(some of them just have fields.)
public class WS_IN_SimpayTransaction
{
[DataMember]
public WS_IN_WebServiceIdentity wsIdentity;
[DataMember]
public WS_IN_SimpayTransactionParams simpayTransactionParams;
}
public class WS_IN_WebServiceIdentity
{
private string WS_userName;
private string WS_passWord;
public string WS_UserName
{
set { this.WS_userName = value; }
get { return this.WS_userName; }
}
public string WS_PassWord
{
set { this.WS_passWord = value; }
get { return this.WS_passWord; }
}
}
public class WS_IN_SimpayTransactionParams
{
string amount;
string itemDes;
string productID;
string mobileNumber;
string bankType;
double bankTransactionID;
int transID;
DateTime date;
public string Amount
{
set { amount = value; }
get { return amount; }
}
public string ItemDes
{
set { itemDes = value; }
get { return itemDes; }
}
public string ProductID
{
set { productID = value; }
get { return productID; }
}
public string MobileNumber
{
set { mobileNumber = value; }
get { return mobileNumber; }
}
public string BankType
{
set { bankType = value; }
get { return bankType; }
}
public double BankTransactionID
{
set { bankTransactionID = value; }
get { return bankTransactionID; }
}
public int TransID
{
set { transID = value; }
get { return transID; }
}
public DateTime Date
{
set { date = value; }
get { return date; }
}
}
long story short. its a little complicated.