How to write class-dependant transformations?

This code snippet might be what you are looking for.