public int NumberOfVisibleFields(bool considerAlwaysShow = true) { int size = 0; MetaMetadataOneLevelNestingEnumerator fullEnumerator = FullNonRecursiveMetaMetadataIterator(); // iterate over all fields in this & then in each mixin of this while (fullEnumerator.MoveNext()) { MetaMetadataField metaMetadataField = fullEnumerator.Current; MetaMetadataField metaMetadata = fullEnumerator.CurrentObject(); // stays the same for until we // iterate over all mfd's for // it Metadata currentMetadata = fullEnumerator.CurrentMetadata; // When the iterator enters the metadata in the mixins "this" in getValueString has to be // the corresponding metadata in mixin. bool hasVisibleNonNullField = false; MetadataFieldDescriptor mfd = metaMetadataField.MetadataFieldDescriptor; if (metaMetadata.IsChildFieldDisplayed(metaMetadataField.Name)) { if (mfd.IsScalar && !mfd.IsCollection) { hasVisibleNonNullField = MetadataString.IsNotNullAndEmptyValue(mfd.GetValueString(currentMetadata)); } else if (mfd.IsComposite) { Metadata nestedMetadata = (Metadata)mfd.GetNestedMetadata(currentMetadata); hasVisibleNonNullField = (nestedMetadata != null) ? (nestedMetadata.NumberOfVisibleFields() > 0) : false; } else if (mfd.IsCollection) { ICollection collection = mfd.GetCollection(currentMetadata); hasVisibleNonNullField = (collection != null) ? (collection.Count > 0) : false; } } // "null" happens with mixins fieldAccessor b'coz getValueString() returns "null". // TODO use MetaMetadataField.numNonDisplayedFields() bool isVisibleField = !metaMetadataField.Hide && ((considerAlwaysShow && metaMetadataField.AlwaysShow) || hasVisibleNonNullField); if (isVisibleField) { size++; } } return(size); }