News for hackers. Stuff that matters.

hyperlinq

Re:Aramid: Create Strongly-Typed HTML Components in C# on Monday November 14, 2016 @12:53PM (#12951707)
You may want to check out Hyperlinq, a C# library for statically typed HTML generation. It also statically types the HTML attributes. Example code:

H.head ( H.title ("Hello world"), H.link (a => a.href ("/favicon.ico").rel ("shortcut icon").type ("image/x-icon")) )

Having used it on a website that I've had to maintain for years I can say that the simplicity of writing reusable components and ease of refactoring is really nice. It entirely negates the need to use a view mechanism at all - you just write your views in C# code.

The links for github and nuget are:

https://github.com/hyperlinq/hyperlinq https://www.nuget.org/packages/Hyperlinq

I should mention that I use Hyperlinq in conjunction with MarkdownDeep. Markdown is great for defining HTML fragments that are very document-oriented, as opposed to data-oriented. So for instance I'd use markdown to define an FAQ, but would use Hyperlinq to define HTML for a customer record. Markdown fragments can be inserted into a Hyperlinq DOM as literal nodes (the underlying mechanism for Hyperlinq is Linq to XML), so the two approaches mesh together nicely.

I wrote the library ages ago but put very little effort into promoting it as I'm too busy.