/// <summary> /// Intercepts the given <see cref="ControlCollection"/> by dynamically deriving /// the original type and let it implement <see cref="ISupportsWebDependencyInjection"/>. /// </summary> /// <param name="defaultApplicationContext">the ApplicationContext to be set on the collection instance.</param> /// <param name="ctlAccessor">a wrapper around the owner control instance.</param> /// <param name="ctlColAccessor">a wrapper around the collection instance.</param> /// <returns><value>true</value>, if interception was successful. <value>false</value> otherwise</returns> public bool Intercept(IApplicationContext defaultApplicationContext, ControlAccessor ctlAccessor, ControlCollectionAccessor ctlColAccessor) { Type collectionType = ctlColAccessor.GetTargetType(); if (collectionType.IsSealed || !ReflectionUtils.IsTypeVisible(collectionType, DynamicProxyManager.ASSEMBLY_NAME)) // || (null == collectionType.GetConstructor(new Type[] {typeof (Control)})) { return false; } // this will enhance the collection's type and create a new instance of this type with fields copied from original collection try { ControlCollection childControls = InterceptCollection(ctlAccessor.GetTarget(), ctlColAccessor.GetTarget() ); ((ISupportsWebDependencyInjection)childControls).DefaultApplicationContext = defaultApplicationContext; ctlAccessor.Controls = childControls; } catch { // this may happen, if the ControlCollection doesn't contain a standard-ctor ControlCollection( Control owner) return false; } return true; }
/// <summary> /// Intercepts the given <see cref="ControlCollection"/> by dynamically deriving /// the original type and let it implement <see cref="ISupportsWebDependencyInjection"/>. /// </summary> /// <param name="defaultApplicationContext">the ApplicationContext to be set on the collection instance.</param> /// <param name="ctlAccessor">a wrapper around the owner control instance.</param> /// <param name="ctlColAccessor">a wrapper around the collection instance.</param> /// <returns><value>true</value>, if interception was successful. <value>false</value> otherwise</returns> public bool Intercept(IApplicationContext defaultApplicationContext, ControlAccessor ctlAccessor, ControlCollectionAccessor ctlColAccessor) { Type collectionType = ctlColAccessor.GetTargetType(); if (collectionType.IsSealed || !ReflectionUtils.IsTypeVisible(collectionType, DynamicProxyManager.ASSEMBLY_NAME)) // || (null == collectionType.GetConstructor(new Type[] {typeof (Control)})) { return(false); } // this will enhance the collection's type and create a new instance of this type with fields copied from original collection try { ControlCollection childControls = InterceptCollection(ctlAccessor.GetTarget(), ctlColAccessor.GetTarget()); ((ISupportsWebDependencyInjection)childControls).DefaultApplicationContext = defaultApplicationContext; ctlAccessor.Controls = childControls; } catch { // this may happen, if the ControlCollection doesn't contain a standard-ctor ControlCollection( Control owner) return(false); } return(true); }