I haven't worked with Reflection since the last time I touched Java and I'm a little rusty. I've created a Windows service that uses timers and for some of the classes I need the object name to be dynamic (pulled from a sql table). The scope of the objects' creation is within a while loop and I need to be able to save each object's properties.
EDIT:
Ended up using a dictionary so that I can retrieve each object's properties later.
private void GetActiveScans()
{
string sql = "SELECT * FROM scans WHERE enabled = 1";
SqlConnection sqlconn = new SqlConnection(connectionString);
sqlconn.Open();
SqlCommand cmd = new SqlCommand(sql, sqlconn);
SqlDataReader drActiveScans = cmd.ExecuteReader(CommandBehavior.CloseConnection);
Dictionary<int, WindowsServiceAudit> WSA = new Dictionary<int, WindowsServiceAudit>();
while (drActiveScans.Read())
{
string tmpscantype = drActiveScans["scantype"].ToString();
switch (tmpscantype)
{
case "services":
int scanid = Convert.ToInt32(drActiveScans["scanid"]);
string scanname = drActiveScans["scanname"].ToString();
int serverclass = Convert.ToInt32(drActiveScans["serverclass"]);
int interval = Convert.ToInt32(drActiveScans["interval"]);
WindowsServiceAudit x = new WindowsServiceAudit(scanid, scanname, serverclass, interval);
WSA.Add(scanid, x);
break;
}
}
}