예제 #1
0
        public TemplateObject Clone()
        {
            TemplateObject obj = new TemplateObject();

            obj.Id           = Id;
            obj.DemoInput    = DemoInput;
            obj.Information  = Information;
            obj.OuterHTML    = OuterHTML;
            obj.InnerHTML    = InnerHTML;
            obj.Category     = Category;
            obj.DisplayName  = DisplayName;
            obj.DataType     = DataType;
            obj.CssName      = CssName;
            obj.DefaultValue = DefaultValue;
            obj.ShowTitle    = ShowTitle;
            obj.TitleWidth   = TitleWidth;
            obj.InputWidth   = InputWidth;
            obj.InputHeight  = InputHeight;
            obj.NoUse        = NoUse;
            return(obj);
        }
        public static TemplateObject AnalyseTemplate(string html)
        {
            if (string.IsNullOrEmpty(html))
            {
                throw new ArgumentException("分析模板 - 参数不能为空。", "html");
            }
            TemplateObject info = new TemplateObject();

            #region 外部文本

            info.OuterHTML = html;

            #endregion

            #region 内部文本

            Regex regex_InnerText = new Regex(Pattern_InnerText, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            Match match_InnerText = regex_InnerText.Match(html, 0);
            if (match_InnerText.Success)
            {
                info.InnerHTML = match_InnerText.Value;
            }
            else
            {
                info.InnerHTML = string.Empty;
            }

            #endregion

            #region 模板分类

            Regex regex_Category = new Regex(Pattern_Category, RegexOptions.IgnoreCase);
            Match match_Category = regex_Category.Match(html, 0);
            if (match_Category.Success)
            {
                info.Category = match_Category.Value;
            }
            else
            {
                info.Category = string.Empty;
            }

            #endregion

            #region 属性

            Regex regex_Properties = new Regex(Pattern_Properties, RegexOptions.IgnoreCase);
            Match match_Properties = regex_Properties.Match(html, 0);
            if (match_Properties.Success)
            {
                Regex regex_Property = new Regex(Pattern_Property, RegexOptions.IgnoreCase);
                Match match_Property = regex_Property.Match(match_Properties.Value, 0);
                while (match_Property.Success)
                {
                    string text  = match_Property.Value;
                    int    index = text.IndexOf("=");
                    string title = text.Substring(0, index);
                    string value = text.Substring(index + 1).Trim('"');
                    switch (title.ToLower())
                    {
                    case "id":
                        info.Id = value;
                        break;

                    case "displayname":
                        info.DisplayName = value;
                        break;

                    case "cssname":
                        info.CssName = value;
                        break;

                    case "datatype":
                        info.DataType = value;
                        break;

                    case "datasource":
                        info.DataSource = value;
                        break;

                    case "defaultvalue":
                        info.DefaultValue = value;
                        break;

                    case "showtitle":
                        info.ShowTitle = bool.Parse(value);
                        break;

                    case "demoinput":
                        info.DemoInput = value;
                        break;

                    case "information":
                        info.Information = value;
                        break;

                    case "showthis":
                        info.ShowThis = bool.Parse(value);
                        break;

                    case "index":
                        info.Index = int.Parse(value);
                        break;

                    case "titlewidth":
                        info.TitleWidth = int.Parse(value);
                        break;

                    case "inputwidth":
                        info.InputWidth = int.Parse(value);
                        break;

                    case "inputheight":
                        info.InputHeight = int.Parse(value);
                        break;

                    case "nouse":
                        info.NoUse = bool.Parse(value);
                        break;
                    }

                    match_Property = match_Property.NextMatch();
                }
            }

            #endregion

            return(info);
        }