I am updating the system and looking at another developer code (ASP.NET in C #).
I came across this:
private ReferralSearchFilterResults ReferralsMatched
{
get
{
if (Session[SESSION_REFERRAL_SEARCHFILTERRESULTS] == null || Session[SESSION_REFERRAL_SEARCHFILTERRESULTS].GetType() != typeof(ReferralSearchFilterResults))
return null;
else
return (ReferralSearchFilterResults)Session[SESSION_REFERRAL_SEARCHFILTERRESULTS];
}
set
{
if (value == null)
{
Session[SESSION_REFERRAL_SEARCHFILTERRESULTS] = value;
}
else if (value.GetType() == typeof(ReferralSearchFilterResults))
{
Session[SESSION_REFERRAL_SEARCHFILTERRESULTS] = value;
}
}
}
Is type checking on a setter unnecessary? Of course, if I set the property for something other than an object ReferralSearchFilterResults, the code will not even compile? Am I missing something, or am I right to think that this can only be achieved with:
set
{
Session[SESSION_REFERRAL_SEARCHFILTERRESULTS] = value;
}
Jamie source
share