/// <summary> /// Parses the given string and fires the selector event handler. /// </summary> /// <param name="main">Main class</param> /// <param name="source">Styles to parse</param> public void ParseStylesheet(CssParser main, string source) { if (source != null) { styles = new List <StyleObject>(); Match match; // remove all comments as we don't parse these properly source = StyleComment.Replace(source, ""); // get selectors if ((match = StyleSelectorRegex.Match(source, 0)).Success) { do { CaptureCollection selectors = match.Groups["selectors"].Captures; CaptureCollection cssText = match.Groups["csstext"].Captures; for (int i = 0; i < selectors.Count; i++) { so = new StyleObject(); GetStyleObject(cssText[i].ToString()); // create StyleObject from { content } String sn = selectors[i].ToString(); SelectorType st = GetSelectorType(selectors[i].ToString()); so.SelectorName = sn; so.SelectorType = st; styles.Add(so); main.OnSelectorReady(so); } match = match.NextMatch(); } while (match.Success); } } }
/// <summary> /// This method fires the <see cref="SelectorReady"/> event and informs the caller /// in this way that a selector was found. /// </summary> /// <param name="so"></param> internal void OnSelectorReady(StyleObject so) { if (SelectorReady != null) { SelectorEventArgs args = new SelectorEventArgs(); args.Name = so.SelectorName; args.Type = so.SelectorType; args.Selector = so; SelectorReady(this, args); } }