我得到了从我的抽象基类继承的所有类,如下所示:
# Observer that watches for Macro Dropdown change and updates dropdowns
observeEvent({
req(input$fMIDdropDown)
req(input$RMDD1)
input$RMDD1
input$RMDD2
input$RMDD3
input$RMDD4
input$RMDD5
input$RMDD6
input$RMDD7
input$RMDD8 }, ignoreNULL = FALSE, ignoreInit = T, priority = 10, {
disable("SubmitDD")
disable("ClearDD")
disable("RMDD1")
disable("RMDD2")
disable("RMDD3")
disable("RMDD4")
disable("RMDD5")
disable("RMDD6")
disable("RMDD7")
disable("RMDD8")
RMDD1 <- ifelse(!is.null(input$RMDD1), input$RMDD1, "%")
RMDD2 <- ifelse(!is.null(input$RMDD2), input$RMDD2, "%")
RMDD3 <- ifelse(!is.null(input$RMDD3), input$RMDD3, "%")
RMDD4 <- ifelse(!is.null(input$RMDD4), input$RMDD4, "%")
RMDD5 <- ifelse(!is.null(input$RMDD5), input$RMDD5, "%")
RMDD6 <- ifelse(!is.null(input$RMDD6), input$RMDD6, "%")
RMDD7 <- ifelse(!is.null(input$RMDD7), input$RMDD7, "%")
RMDD8 <- ifelse(!is.null(input$RMDD8), input$RMDD8, "%")
TemplateName <- input$TemplatedropDown
MIDIndex <- MIDTable$macro_product_id[input$fMIDdropDown == MIDTable$product_name]
#### Capture Selected Forecast Start Date
StartDate <- as.Date(input$ForecastStartDD, "%Y-%m-%d")
StartYear <- as.numeric(format(StartDate, "%Y"))
StartMonth <- as.numeric(format(StartDate, "%m"))
#### Get Forecast Set ID associated with MID and Start Date
ForecastSet <- GetForecastSetByDate(MIDIndex, StartYear, StartMonth)[1,1]
lapply(length(GetDropDownNames(MIDIndex)[[1]]):1, function(j) {
# Progress Bar for drop down build
withProgress(message = 'Updating drop down selector', detail = j, value = 0, {
for (n in 1:1) { incProgress(1) }
})
ValSelect <- input[[paste0("RMDD", j)]]
DDTitle <- GetDropDownNames(MIDIndex)[j,1]
DDValues <- UpdateDropDowns(paste0("source_attribute_", j),
MIDIndex,
ForecastSet,
TemplateName,
RMDD1,
RMDD2,
RMDD3,
RMDD4,
RMDD5,
RMDD6,
RMDD7,
RMDD8)[,1]
updateSelectizeInput(session,
inputId = paste0("RMDD", j),
DDTitle,
DDValues,
selected = ValSelect,
options = list(maxOptions = 100000)
)
})
}
)
现在我可以以某种方式获取所有这些类的所有/任何实例吗?这还属于反射吗?
答案 0 :(得分:0)
如果您使所有单身人士实现一个接口,例如ISingleton
,并且用一个方法返回实例,我们将其称为GetInstance
,这将是最简单的。然后,您可以枚举ISingleton
中具有GetInterfaces()
的所有类型,通过反射捕获GetInstance
方法并调用它。
无法简单地找到给定类型的所有实例,因为您将不得不以某种方式遍历所有正在运行的线程的整个分配堆空间和堆栈空间,这至少很难实现。 。