SIL.FieldWorks.XWorks.DTMenuHandler.CanInsertFieldIntoObj C# (CSharp) Method

CanInsertFieldIntoObj() protected method

Check if the field can be inserted into the given object.
protected CanInsertFieldIntoObj ( SIL.FieldWorks.FDO.FdoCache fdoCache, string fieldName, ICmObject parentObj, int &index ) : bool
fdoCache SIL.FieldWorks.FDO.FdoCache
fieldName string name of the field to be inserted
parentObj ICmObject The object where the item would be inserted, if possible.
index int index (0-based) where it will be inserted. -1 if atomic or returns false
return bool
		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;
		}