Exemplo n.º 1
0
        /// <summary>
        /// Perform the actual insertion</summary>
        /// <param name="context">Must implement IHierarchicalInsertionContext and/or
        /// IInstancingContext to succeed</param>
        /// <param name="parent">Optional. Parent object to which the new child is added. Can be null
        /// if the context supports it.</param>
        /// <param name="child">New child object to be inserted into the specified parent</param>
        private static void DoInsert(object context, object parent, object child)
        {
            IHierarchicalInsertionContext hierarchicalInsertionContext = context.As <IHierarchicalInsertionContext>();

            if (hierarchicalInsertionContext != null)
            {
                hierarchicalInsertionContext.Insert(parent, child);
            }
            else
            {
                IInstancingContext instancingContext = context.As <IInstancingContext>();
                if (instancingContext != null)
                {
                    instancingContext.Insert(child);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Indicates if the specified child can be inserted into the specified parent object</summary>
        /// <param name="context">Must implement IHierarchicalInsertionContext and/or
        /// IInstancingContext to succeed</param>
        /// <param name="parent">Optional. Parent object we want to insert into. Can be null if the
        /// context supports it.</param>
        /// <param name="child">Child object to be inserted into the specified parent</param>
        /// <returns>True iff the child can be inserted into the parent (or the context supports
        /// parent-less insertion)</returns>
        /// <remarks>The context must implement IHierarchicalInsertionContext and/or IInstancingContext
        /// to allow insertion. If the context implements both, IHierarchicalInsertionContext is preferred and
        /// any insertion logic in the IInstancingContext implementation is ignored!</remarks>
        public static bool CanInsert(object context, object parent, object child)
        {
            IHierarchicalInsertionContext hierarchicalInsertionContext = context.As <IHierarchicalInsertionContext>();

            if (hierarchicalInsertionContext != null)
            {
                return(hierarchicalInsertionContext.CanInsert(parent, child));
            }
            else
            {
                IInstancingContext instancingContext = context.As <IInstancingContext>();
                if (instancingContext != null)
                {
                    return(instancingContext.CanInsert(child));
                }
            }

            return(false);
        }