示例#1
0
        ///<summary>
        ///Converts a style sheet to HtmlClass
        ///</summary>
        ///<param name="sec">Style sheet</param>
        ///<returns>HtmlClass</returns>
        public HtmlClass Parser(String CascadingStyleSheet)
        {
            HtmlClass result=null;

            if (!String.IsNullOrEmpty(CascadingStyleSheet))
            {
                 result = new HtmlClass();
                //Remove comments
                MatchCollection MatchList = rStyles.Matches(Regex.Replace(CascadingStyleSheet, CSSComments, String.Empty));
                foreach (Match item in MatchList)
                {
                    if (item != null && item.Groups != null && item.Groups["selector"] != null &&
                        item.Groups["selector"].Captures != null && item.Groups["selector"].Captures[0] != null
                        && !String.IsNullOrEmpty(item.Groups["selector"].Value))
                    {
                        String classname = item.Groups["selector"].Captures[0].Value.Trim();
                        HtmlStyle style = new HtmlStyle();

                        if (classname.Trim().Length > 0)
                        {
                            foreach (string cn in classname.Split(','))
                            {
                                string nameclass = cn;
                                nameclass = nameclass.Replace("\n", "");
                                nameclass = nameclass.Replace("\r", "");
                                classType typeOfClass = classType.styleClass;
                                if (nameclass.StartsWith("."))
                                {
                                    nameclass = nameclass.Substring(1, nameclass.Length - 1);
                                    typeOfClass = classType.styleClass;
                                }
                                else if (nameclass.StartsWith("#"))
                                {
                                    nameclass = nameclass.Substring(1, nameclass.Length - 1);
                                    typeOfClass = classType.styleIdElement;
                                }
                                else
                                    typeOfClass = classType.styleTypeElement;

                                for (int i = 0; i < item.Groups["name"].Captures.Count; i++)
                                {
                                    String styleproperty = item.Groups["name"].Captures[i].Value;
                                    String valueproperty = item.Groups["value"].Captures[i].Value;
                                    style = new SetStyle().AddPropertyValue(styleproperty, valueproperty, style);

                                }
                                result.AddClass(nameclass, style, typeOfClass);
                            }
                        }
                    }
                }
            }
            //up here are implemented styles in style tags

            //from here i implement elements what not are implemented in style tag
            //todo ...
            return result;
        }
示例#2
0
        ///<summary>
        ///returns:
        /// 1 if the class already exists and has been replaced by the 2º parameter
        /// 2 if the class was successfully added
        /// 3 no class has been added
        ///</summary>
        public int SetClass(string classname,HtmlStyle style )
        {
            var s = from st in listClass
                    where st.Name == classname
                    select st;

            if (s != null)
                if (s.Count() > 0)
                {
                    s.First().CssClass = style;
                    return 1;
                }

            if (AddClass(classname, style))
                return 2;
            return 0;
        }
示例#3
0
 public bool RemoveClass(string classname, HtmlStyle style)
 {
     var s = from st in listClass
             where st.Name == classname
             select st;
     if (s != null)
         if (s.Count() > 0)
             return listClass.Remove(s.First());
     return false;
 }
示例#4
0
        public bool AddClass(string classname,HtmlStyle style)
        {
            var s = from st in listClass
                    where st.Name == classname
                    select st;

            if (s != null)
                if (s.Count() > 0)
                    return false;

            ListClass.Add(new ClassCss() { CssClass = style, Name = classname });
            return true;
        }
示例#5
0
 public HtmlStyle addStyleValue(string key, string value, HtmlStyle style )
 {
     this.styleResult = style;
     addStyle(key, value);
      return styleResult;
 }
示例#6
0
 public HtmlStyle AddPropertyValue(string name, string value, HtmlStyle style)
 {
     return new PrepareStyle().addStyleValue(name, value, style);
 }
示例#7
0
        public HtmlStyle AddStyle(HtmlStyle addstyle)
        {
            foreach (var a in addstyle.GetType().GetProperties())
            {
                var v = a.GetValue(addstyle, null);
                ValueStyle vstyle = v as ValueStyle;
                if (vstyle != null)
                {
                    if(vstyle.hasValue())
                    {
                        var vs= vstyle.GetValue();
                        if (vs != null)
                        {
                            this.GetType().GetProperty(a.Name).SetValue(this,v,null);
                        }

                    }
                }

            }
            return this;
        }