龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > asp.net编程 >

asp.net开发WAP网站及集成在线wap模拟器(5)

时间:2009-12-21 11:47来源:未知 作者:admin 点击:
分享到:
ParamRules实现如下: Code [http://www.xueit.com] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace Rsion.Web{ /// summary ///

ParamRules实现如下:

 

Code [http://www.xueit.com]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Rsion.Web
{
    /// <summary>
    /// 模板参数规则类
    /// </summary>
    public class ParamRules:IEnumerable
    {
        private Dictionary<string, object> rules;

        public ParamRules()
        {
            if (rules == null) rules = new Dictionary<string, object>();
        }

        public object this[string paramKey]
        {
            get
            {
                if (rules.ContainsKey(paramKey)) return rules[paramKey];
                return "";
            }
            set
            {
                if (rules.ContainsKey(paramKey)) rules[paramKey] = value;
                else rules.Add(paramKey, value);
            }
        }
        /// <summary>
        /// 添加新的规则
        /// </summary>
        /// <param name="paramKey"></param>
        /// <param name="paramValue"></param>
        public void Add(string paramKey, object paramValue)
        {
            if (rules.ContainsKey(paramKey))
                throw new ArgumentException("对不起规则已经存在!Key:"   paramKey   ",Value:"   rules[paramKey].ToString(), "paramKey");
            rules.Add(paramKey, paramValue);
        }

        public void Remove(string paramKey, object paramValue)
        {
            if (rules.ContainsKey(paramKey))
                rules.Remove(paramKey);
        }

        #region IEnumerable 成员

        public IEnumerator GetEnumerator()
        {
            foreach (KeyValuePair<string, object> k in rules)
            {
                yield return k;
            }
        }

        #endregion
    }
}

Template.cs实现如下:

 

Code [http://www.xueit.com]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rsion.Web
{
    /// <summary>
    /// 模板
    /// </summary>
    public class Template
    {
        public static Template _template;
        private static ParamRules rules;

        private Template() { }

        public static Template CreateInstance()
        {
            if (_template == null) _template = new Template();
            return _template;
        }
        public ParamRules Rules
        {
            get
            {
                if (rules == null) rules = new ParamRules();
                return rules;
            }
        }
        
    }
}

这样我们先在global.asax中填加一些模板数据,这样才可以解析模板,解析模板的功能实现在PageAdapter中,这样可以
在本页面直接调用Html.RenderPartial("template")调用


精彩图集

赞助商链接