I have a winform app for in house use where the below is very common.
Int32? afhAgreement = null;
if (!lkuReveiewAFHAgreement.Text.Equals(string.Empty))
{
afhAgreement = (Int32)lkuReveiewAFHAgreement.EditValue;
}
DateTime? afhAgreementDate = null;
if (datAFHAgreementCompleted.Text != String.Empty)
{
afhAgreementDate = (DateTime?)datAFHAgreementCompleted.EditValue;
}
Int32? crisisPlan = null;
if (!lkuReview6MonthCrisisPlan.Text.Equals(string.Empty))
{
crisisPlan = (Int32)lkuReview6MonthCrisisPlan.EditValue;
}
DateTime? crisisPlanDate = null;
if (dat6MonthCrisisPlanReviewed.Text != String.Empty)
{
crisisPlanDate = (DateTime?)dat6MonthCrisisPlanReviewed.EditValue;
}
Int32? riskAgreement = null;
if (!lkuReviewRiskAssessment.Text.Equals(string.Empty))
{
riskAgreement = (Int32)lkuReviewRiskAssessment.EditValue;
}
DateTime? riskAgreementDate = null;
if (!datRiskAssessmentReviewed.Text.Equals(string.Empty))
{
riskAgreementDate = (DateTime?)datRiskAssessmentReviewed.EditValue;
}
Seeing as all of those variables can be NULL
it seems like this is a ridiculous way to do this. Isn't there a Convert this object and Default to NULL
?
By the way, EditValue
is an object though I believe I have the same issue even if I use the Text
property of the control.
So, is there a better way? Is this something I could simplify with Extension Methods
?