Hi Guys,

I'm writing a program for work which uses the HtmlTextWriter to output html files (it's a reporting system). In each file I want to render a style tag at the beginning and to do this I'm using the HtmlTextWriterStyle enumeration.

This means I need to convert any value belonging to this enumeration into its equivalent html formatted string. Ideally, I'd like to make use of the GetStyleName function in HtmlTextWriter, but that's a private function :(.

Note: The enumerations ToString function doesn't convert the styles to syntactically correct Html.



In case anyone was wondering, I've just hacked together a solution for now... but it'd be nice if somebody came up with something cleaner... :P

System::String^ HtmlStyle::GetStyleString(System::Web::UI::HtmlTextWriterStyle style)
  String^ str = style.ToString();  

  // Skip the first char
  for(int i = 1; i < str->Length; i++)
      str = str->Insert(i, "-");
  return str->ToLower();

This solution assumes that for every upper case letter in a style (the string versions are always something like FontSize) bar the first, will have a dash before them in the syntactically correct Html.