It's So Ugly...

time to read 1 min | 131 words

I’m trying to tag a type with an image. Because the CLR doesn’t support static interfaces, I need to use an attribute with a string that points to the correct resource. Lie this: [WithImage(“ImageId”)]

 

The problem is with the code that loads the image on runtime. It is so fragile that I can’t stand it.

 

string baseName = type.Assembly.FullName.Split(',')[0]+ ".Properties.Resources";

ResourceManager rm = new ResourceManager(baseName, type.Assembly);

image = (Image) rm.GetObject(imageResourceId);

 

There has got to be a better way than this, any ideas?