Using getElementsBySelector in ScriptSharp

I’m on my way to my second spike for one of my clients on playing with ScriptSharp to extend Rasta with Ajax functionality, and really wanted to be able to select elements as I would in CSS, using selectors (something I got quite used to with jQuery).

ScriptSharp comes with various assemblies you can link to. The one called sscorlib is a .net mapping over a javascript library that extends document to have a getElementsBySelector method. But for some reason, ScriptSharp doesn’t map that method.

So how do you call random code in ScriptSharp without resorting to evil eval code? You create a function of course! Here’s the snippet.

        public static DOMElement[] GetElementsBySelector(string selector, DOMElement root)


            return new Function("return document.getElementsBySelector(selector, arg);", "selector", "arg")

                .Call(Document.DocumentElement, selector, root) as DOMElement[];


We define a function that calls the correct javascript code, declare the argument names we will pass it, and finally call it by passing our selector and the root.

In one word, sweet.


Received this morning

Dear Sebastien

We are currently searching for a JOB TITLE to work in  CITY, COUNTRY  for DURATION plus extensions. This is a fantastic contract opportunity for a large multi-national client.

The ideal candidate must have the following skills: SHORT JOB DESCRIPTION.

A nice way to start the morning! Where do I sign?


“It doesn’t work”

Something seriously cracks me up. I hear day after day people telling me one technology or another, one tool or another, fails in matching their expectation, and explain the situation by it doesn’t work.

As soon as those words are muttered by someone in a team with low knowledge of the toolkit they are dealing with, you see developers running around to work around the symptom, replace the technology, or completely screw up an architecture or a design just to make it work.

Just the same, while TDD and fast feedback cycles have brought to the development community an antidote to the press F5, it works, I’m l33t, you still find a large number of rogue developers that still manage to write no test, go head down in development, produce unmaintainable code and still manage to lift it off because the UI is shiny and the managers don’t have a clue about the importance of quality and maintainability, as they don’t have the responsibility of their v2 budget.

Whenever faced with an intellectual challenge, you have two categories of people: those who step up, learn and understand a problem before finding a solution, and the it doesn’t work and Oh I press F5 I’m good! developers. My word of advice to the latter, if you are given guidance and mentoring and refuse to step up, you will eventually be out of work. Embrace change, challenge yourself and don’t discard mentoring when it’s given to you.