Exemple #1
0
        public static CslaObjectInfo FindParentObject(this CslaObjectInfo info)
        {
            CslaObjectInfo parentInfo = null;

            if (string.IsNullOrEmpty(info.ParentType))
            {
                // no parent specified; find the object whose child is this object
                foreach (var cslaObject in info.Parent.CslaObjects)
                {
                    foreach (var childProperty in cslaObject.GetAllChildProperties())
                    {
                        if (childProperty.TypeName == info.ObjectName)
                        {
                            parentInfo = cslaObject;
                        }
                    }
                    if (parentInfo != null)
                    {
                        break;
                    }
                }
            }
            else
            {
                parentInfo = info.Parent.CslaObjects.Find(info.ParentType);
            }

            if (parentInfo != null)
            {
                if (parentInfo.ItemType == info.ObjectName)
                {
                    return(parentInfo.FindParentObject());
                }

                if (parentInfo.GetAllChildProperties().FindType(info.ObjectName) != null)
                {
                    return(parentInfo);
                }

                /*if (parentInfo.GetCollectionChildProperties().FindType(info.ObjectName) != null)
                 *  return parentInfo;*/
            }

            return(null);
        }