protected bool CanInsertFieldIntoObj(FdoCache fdoCache, string fieldName, ICmObject parentObj, out int index)
{
index = -1; // atomic or not possible
if (fdoCache == null || parentObj == null || (!parentObj.IsValidObject) || String.IsNullOrEmpty(fieldName))
return false;
var mdc = fdoCache.ServiceLocator.GetInstance<IFwMetaDataCacheManaged>();
// class not specified, depends on the object we're testing.
int flid = GetFlidIfPossible(parentObj.ClassID, fieldName, mdc);
if (flid == 0)
return false; // Some kind of fake field, or wrong type of object, so bail out.
var type = (CellarPropertyType) mdc.GetFieldType(flid);
// we can only insert new objects into virtual reference properties
if (fdoCache.IsReferenceProperty(flid) && !mdc.get_IsVirtual(flid))
return false;
if (type == CellarPropertyType.OwningSequence ||
type == CellarPropertyType.OwningCollection ||
type == CellarPropertyType.ReferenceCollection ||
type == CellarPropertyType.ReferenceSequence)
{
index = fdoCache.DomainDataByFlid.get_VecSize(parentObj.Hvo, flid);
return true;
}
// if its an atomic field, see if it's already been filled.
if (type == CellarPropertyType.OwningAtomic || type == CellarPropertyType.ReferenceAtomic)
{
return fdoCache.DomainDataByFlid.get_ObjectProp(parentObj.Hvo, flid) == 0;
}
return false;
}