Screen-Cast: Writing a Custom Axis Method

Return to the RPFT Screen-Cast SeriesSometimes the easiest way to accomplish a particular task is to write an axis method that returns just the elements in an Open XML document that you are interested in. Sometimes you want to write the axis method in a lazy fashion so that it performs as well as possible on large documents. You also may need to use some form or another of recursion as the easiest way to write your axis method. However, recursion and laziness are at odds. You can’t write a method that uses ‘yield return’ in some places (to implement laziness) and uses ‘return’ in other places to implement recursion. This screen-cast shows how to get around this limitation in the C# language.

To demonstrate this scenario, I write an axis method that returns just certain runs of a WordprocessingML document, in document order.