TemplatedWebControl类的源代码

类图:



下面是该类的详细分析:


作用:

 /// The base class for ALL community server controls that must load their UI either through an external skin
 /// or via an in-page template.

CreateChildControls()方法:
功能说明:

1.如果存在自定义风格设置(custom theme setting)就首先加载该设置
2.如果条件1不满足,就检查是否存在内嵌模板,如果存在,就加载该内嵌模板。
  其中内嵌模板由调用该类的方法通过SkinTemplate公共属性来设置
3.如果条件1、2都不满足,就检查是否存在默认皮肤设置文件(DefaultSkinFileExists),如果存在,就加载该设置
4.如果条件1、2、3均不满足,就抛出异常 。

具体代码:


        /// <exclude/>
        protected override void CreateChildControls() {
            Controls.Clear();

            
// 1) A custom theme setting is the most important
            Boolean _skinLoaded = false;
            
if ( !Globals.IsNullorEmpty(ThemeName) ) {
                
if ( SkinFolderExists ) {
                    
if ( SkinFileExists && this.Page != null ) {
                        Control skin 
= this.Page.LoadControl( this.SkinPath );
                        
this.Controls.Add( skin );
                        _skinLoaded 
= true;
                    }
                } 
            } 

            
// 2) Next, look for an inline template
            if ( !_skinLoaded && SkinTemplate != null ) {
                SkinTemplate.InstantiateIn( 
this );
                _skinLoaded 
= true;
            }

            
// 3) last resort is the default external skin
            if ( !_skinLoaded && this.Page != null && this.DefaultSkinFileExists ) {
                Control defaultSkin 
= this.Page.LoadControl( this.DefaultSkinPath );
                
this.Controls.Add( defaultSkin );
                _skinLoaded 
= true;
            }

            
// 4) If none of the skin locations were successful, throw.
            if ( !_skinLoaded ) {
                
throw new CSException( CommunityServer.Components.CSExceptionType.SkinNotFound );
            }
                
            AttachChildControls();
        }

这里调用的AttachChildControls方法在该类中是个抽象方法:
        /// <summary>
        
/// Override this method to attach templated or external skin controls to local references.
        
/// </summary>
        
/// <remarks>
        
/// This will only be called if the non-default skin is used.
        
/// </remarks>
        protected abstract void AttachChildControls();

SourceMarker(bool isStart, HtmlTextWriter writer)方法:
作用: 输出跟踪调试信息
备注: (1)
            
[System.Diagnostics.Conditional("DEBUG")]
        表明该方法只有在条件编译参数设置为Debug的时候才会执行
       (2)在该类中,该方法未被调用
posted on 2006-03-28 10:40  今夜太冷  阅读(664)  评论(1)    收藏  举报