I'm having an exceptionally geeky day.
I had a testing form that would allow me to call any of the business services I'm working with, to make sure that the setup was right, and they were working (nothing worse than spending an hour trying to find an error when it turns out that the business service server has gone down).
So I'd written code for each one, when it suddenly occurred to me that what I actually wanted to do was get a list of all the classes in my DataLayer DLL, find the ones that were business calls, and then add them to a combobox, and then create new instances of whichever one was chosen.
This is stuff I've _never_ been able to do before. I assume that some languages allow you to extract this kind of information, but I've never encountered it before. I assume that it was going to be extremely difficult. It turned out to be:
to get the list out.
I'm somewhat stunned by how easy it is.
Creating the necessary class, when chosen from the comboBox is as easy as:
I'm also somewhat stunned by how easy that is.
Also, incredibly gratified that someone has made something remarkably difficult into something extremely easy. Heck, if you can do this kind of thing, you're almost back at having the power of an interpreted language (but with strong typing).
I had a testing form that would allow me to call any of the business services I'm working with, to make sure that the setup was right, and they were working (nothing worse than spending an hour trying to find an error when it turns out that the business service server has gone down).
So I'd written code for each one, when it suddenly occurred to me that what I actually wanted to do was get a list of all the classes in my DataLayer DLL, find the ones that were business calls, and then add them to a combobox, and then create new instances of whichever one was chosen.
This is stuff I've _never_ been able to do before. I assume that some languages allow you to extract this kind of information, but I've never encountered it before. I assume that it was going to be extremely difficult. It turned out to be:
Assembly a = Assembly.LoadWithPartialName("DataControlLayer");
Type geneSISBusinessCallType = typeof(DataControlLayer.GeneSISBusinessCall);
foreach (Type t in a.GetTypes())
{
if (t.IsSubclassOf(geneSISBusinessCallType))
comboBox1.Items.Add(t.Name);
}
to get the list out.
I'm somewhat stunned by how easy it is.
Creating the necessary class, when chosen from the comboBox is as easy as:
Assembly a = Assembly.LoadWithPartialName("DataControlLayer");
string callerName = "DataControlLayer."+(string)comboBox1.Items[comboBox1.SelectedIndex];
DataControlLayer.GeneSISBusinessCall c = (DataControlLayer.GeneSISBusinessCall)a.CreateInstance(callerName);
I'm also somewhat stunned by how easy that is.
Also, incredibly gratified that someone has made something remarkably difficult into something extremely easy. Heck, if you can do this kind of thing, you're almost back at having the power of an interpreted language (but with strong typing).