示例#1
0
        public void ControlCollection()
        {
            FormPoker         poker = new FormPoker();
            ControlCollection col   = poker.GetControlCollection();

            Assert.AreEqual(col.GetType(), typeof(ControlCollection), "A1");
            Assert.IsFalse(col.IsReadOnly, "A2");
            Assert.AreEqual(0, col.Count, "A3");
        }
示例#2
0
 private static IBarraPaginacao FindControlByTypeIBarraPaginacao(ControlCollection controles)
 {
     if (controles != null)
     {
         foreach (Control controle in controles)
         {
             if (controle is IBarraPaginacao || controles.GetType().IsSubclassOf(typeof(IBarraPaginacao)))
             {
                 return((IBarraPaginacao)controle);
             }
             else
             {
                 IBarraPaginacao filho = FindControlByTypeIBarraPaginacao(controle.Controls);
                 if (filho != null)
                 {
                     return(filho);
                 }
             }
         }
     }
     return(null);
 }
 /// <summary>
 /// Creates a new Accessor for a given <see cref="ControlCollection"/>.
 /// </summary>
 /// <param name="controls">The <see cref="ControlCollection"/> to be accessed</param>
 public ControlCollectionAccessor(ControlCollection controls)
 {
     _controls     = controls;
     _controlsType = controls.GetType();
 }
        private static ControlCollection InterceptCollection(Control owner, ControlCollection originalCollection)
        {
            CreateControlCollectionDelegate factoryMethod = GetInterceptedCollectionFactory(owner.GetType(), originalCollection.GetType());
            ControlCollection interceptedCollection       = factoryMethod(owner);

            ReflectionUtils.MemberwiseCopy(originalCollection, interceptedCollection);
            return(interceptedCollection);
        }
        private static void EnsureControlCollectionIntercepted(IApplicationContext defaultApplicationContext, Control control)
        {
            // check the collection
            ControlAccessor   ctlAccessor   = new ControlAccessor(control);
            ControlCollection childControls = ctlAccessor.Controls;

            if (IsDependencyInjectionAware(defaultApplicationContext, childControls))
            {
                return; // nothing more to do
            }

            // check, if the collection's owner has already been intercepted
            ControlCollectionAccessor ctlColAccessor = new ControlCollectionAccessor(childControls);

            if (IsDependencyInjectionAware(defaultApplicationContext, ctlColAccessor.Owner))
            {
                return; // nothing more to do
            }

            // lookup strategy in cache
            IInterceptionStrategy strategy = null;

            lock (s_cachedInterceptionStrategies)
            {
                strategy = (IInterceptionStrategy)s_cachedInterceptionStrategies[control.GetType()];
            }

            if (strategy != null)
            {
                strategy.Intercept(defaultApplicationContext, ctlAccessor, ctlColAccessor);
            }
            else
            {
                // nothing in cache - try well-known strategies for owner resp. child collection type
                strategy = (IInterceptionStrategy)s_knownInterceptionStrategies[control.GetType()];
                if (strategy == null)
                {
                    strategy = (IInterceptionStrategy)s_knownInterceptionStrategies[childControls.GetType()];
                }

                // try intercept using well-known strategy
                if (strategy != null)
                {
                    bool bOk = strategy.Intercept(defaultApplicationContext, ctlAccessor, ctlColAccessor);
                    if (!bOk)
                    {
                        strategy = null;
                    }
                }

                // not well-known or didn't work out
                if (strategy == null)
                {
                    // probe for a strategy
                    bool bOk = false;
                    for (int i = 0; i < s_availableInterceptionStrategies.Length; i++)
                    {
                        strategy = s_availableInterceptionStrategies[i];
                        bOk      = strategy.Intercept(defaultApplicationContext, ctlAccessor, ctlColAccessor);
                        if (bOk)
                        {
                            break;
                        }
                    }
                    if (!bOk)
                    {
                        LogManager.GetLogger(typeof(ControlInterceptor)).Warn(string.Format("dependency injection not supported for control type {0}", ctlAccessor.GetTarget().GetType()));
                        strategy = s_noopInterceptionStrategy;
                    }
                }

                lock (s_cachedInterceptionStrategies)
                {
                    s_cachedInterceptionStrategies[control.GetType()] = strategy;
                }
            }
        }