Pages

Saturday, June 25, 2016

Reflection

Back in the old days, C++ templates were the highest level of code abstraction for me. I loved creating template classes. On the other hand, Reflection, when I first learned about it, it didn't raise such an emotional feeling in me. It seamed like a complicated way to do simple things. About a year ago I was lucky to work with John Volkar from Bayer Healthcare. His project used Reflection to transform between C# data members and DICOM data elements. Recently, while working on another project, this technique came in handy. It's a nice example of how to use the Attribute class to link between a data member and a DICOM tag. Here it is. Thanks John.

First, how to you use it. It's very simple. Use the Tag attribute above the class member like this:

[Tag(0x0010,0x0010)]
public string patient_name;


This just mapped the patient_name member to a DICOM Patient Name data element by using the tag (0010,0010).