After calling Field.HasValue or Field.GetValue(false, x) the two properties ContainsStandardValue and InheritsValueFromOtherItem is unconditionally reset to false.
The problem is the first two rows in the public function Field.GetValue(…)
public string GetValue(bool allowStandardValue, bool allowDefaultValue) { this.containsStandardValue = 0; this.inheritsValueFromOriginalItem = 0; // ... }
This generates problems when working with items that receives their values from the StandardValues or Clones of items.
The same problem has already been spotted in Sitecore 6.4 by Sean Kearney
http://seankearney.com/post/Field-ContainsStandardValue-in-Sitecore-is-Buggy.aspx
I just verified the problem still exist in Sitecore 7.0. I reported the problem with issue number #396060.
Simple workaround, avoid calling HasValue:
// field.Value calls GetValue(true, false) internally which is safe var fieldValue = field.Value; var hasValue = fieldValue != null;