c# - Conditional Assignment of Fields -
i have issue loading in data xml file , saving domain model objects. issue xml file not consistent in not records contain same attributes.
for example in code below variable roundingrule may not exist. can somehow put conditional statement around field skipped if there nothing assign.
var workrule = new workrule { name = (string) element.attribute("name"), customerid = 11, punchroundruleid = roundingrule, effectivedate = effectivedate, exceptionruleid = exceptionrule, paycodedistributionname = paycodedistributionname, daydivideoverride = daydivideoverride, unapprovedovertimepaycodename = unapprovedovertimepaycodename, exceptionrulename = exceptionrulename, };
you'll need this:
var workrule = new { name = element.attribute("name") == null ? "n/a" : (string)element.attribute("name"), };
Comments
Post a Comment