마지막으로 자바를 만져서 조금 녹슬었기 때문에 리플렉션에서 작업하지 않았습니다. 타이머를 사용하는 Windows 서비스를 만들었고 일부 클래스에서는 동적 인 객체 이름이 필요합니다 (SQL 테이블에서 가져옴). 객체 생성의 범위는 while 루프 내에 있으므로 각 객체의 속성을 저장할 수 있어야합니다.C# .NET 동적 객체 이름
편집 : 나중에 각 개체의 속성을 검색 할 수 있도록 사전을 사용하여 종료
.
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;
}
}
}
와우 이것은 지금까지 본 가장 미친 질문입니다! – zvolkov