First of all, are you sure you need more than you asked for? Alex's solution should just work perfectly for your current problem, if it is always so βeasyβ, why bother and add more complexity to it?
Anway, AgilityPack does not have this feature, but it certainly has the .Net Framework. Note that this is all for .Net 4, if you are using an earlier version, things could be a little different. The first one, System.Web.dll comes with the CssStyleCollection Class , this class already has everything built-in that you might want to parse the built-in css, there is only one catch, its constructor is internal, so the solution is a bit hacky. Firstly, to build an instance of the class that you need, it is slightly reflected, the code for this is already done here . Just keep in mind that this works now, but may break in a future version of .Net. All that remains is very simple
CssStyleCollection css = CssStyleTools.Create(); css.Value = "border-top:1px dotted #BBB;margin-top: 0px;font-size:12px"; Console.WriteLine(css["margin-top"]); //prints "0px"
If for some reason you cannot add a link to System.Web (it will be if you use .Net 4 Client Profile), there is always the opportunity to use Reflector.
Personally, I would go with Alex's decision, but it's up to you to decide. :)
source share