Reputation: 1
Is there a way to validate if inside a list of objects the object that i'm currently validating in a foreach has any atribute null without asking for every atribute individually?
I´m trying to validate null atributes inside an object but they are to much and I don´t what to ask indiviualy because the default value if the request returns null will always be 0. Sorry if there is any mistake, but english is not my native languaje.
I was trying to do this:
public class OBJECT
{
public string CODE { get; set; }
public string U_ATRIBUTE1 { get; set; }
public DateTime U_DATE { get; set; }
public string U_ATRIBUTE2 { get; set; }
public string U_ATRIBUTE3 { get; set; }
}
var results = await Login.Connection
.Request("TABLE")
.Filter("(U_ATRIBUTE eq " + item + " )")
.GetAsync<List<OBJECT>>();
foreach (var result in results)
{
// Here is where i´m trying to validate if any atribute is null
// but I don´t what to ask individually
if (OBJECT.U_ATRIBUTE1 == null)
{
OBJECT.U_ATRIBUTE1 = "0";
}
if (OBJECT.U_ATRIBUTE2 == null)
{
OBJECT.U_ATRIBUTE2 = "0";
}
if (OBJECT.U_ATRIBUTE3 == null)
{
OBJECT.U_ATRIBUTE3 = "0";
}
}
Upvotes: 0
Views: 52
Reputation: 592
Ths will return true
if any property of obj
is null
.
var result = obj.GetType().GetProperties().Any(p => p.GetValue(obj) is null);
Upvotes: 2