随笔 - 547  文章 - 213 评论 - 417 阅读 - 107万

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   今夜太冷  阅读(656)  评论(1编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示