This code is very large and seems quite confusing. I tried to refactor it to make it more readable and make the code seem less...(scroll below). However, I am not sure if this can be refactored more.
TableTypeDescriptor baseDecriptor = base.CustomTypeDescriptor as TableTypeDescriptor;
if (this.IsObjectBeingValidated)
return baseDecriptor;
if (base.CustomTypeDescriptor != null)
{
if (baseDecriptor.OldTableDescriptor != null && this.IsNewInCorrection && !this.IsReadOnly)
{
return base.CustomTypeDescriptor;
}
else if (this.Locked)
{
return base.CustomTypeDescriptor;
}
else if (this.ImportedDataMD5 != null && !this.IsReadOnly)
{
return base.CustomTypeDescriptor;
}
else
{
if (baseDecriptor.OldTableDescriptor != null)
{
return baseDecriptor.OldTableDescriptor;
}
else
return base.CustomTypeDescriptor;
}
}
return base.CustomTypeDescriptor;
I then refactored it as follows. Is it possible to refactor it more?
TableTypeDescriptor baseDescriptor = base.CustomTypeDescriptor as TableTypeDescriptor;
if (base.CustomTypeDescriptor != null || !this.IsObjectBeingValidated)
{
if ( (!this.IsReadOnly && (this.IsNewInCorrection || this.ImportedDataMD5 != null)) ||
this.Locked
)
baseDescriptor = base.CustomTypeDescriptor;
else
{
if (baseDescriptor.OldTableDescriptor != null)
baseDescriptor = baseDecriptor.OldTableDescriptor;
else
baseDescriptor = base.CustomTypeDescriptor;
}
}
return baseDescriptor;