【发布时间】:2019-10-05 04:24:07
【问题描述】:
我目前有两个枚举:
public enum LigneComponent
{
LIEN = 0,
SUPPORT = 1,
OUVRAGE = 2,
}
public enum PosteComponent
{
BT = 0,
COMPTEUR = 1,
AMM = 2,
TFM = 3,
HTA = 4,
DLD = 5,
GENERALITES = 6
}
我正在另一个类中使用其中一个枚举:
public class ExcelReader
{
internal Dictionary<InfosPosteViewModel.PosteComponent, StorageFile> ExcelDataFiles { get; set; }
internal async Task SetupExcelFiles(Dictionary<InfosPosteViewModel.PosteComponent, string> fileKeyNames, StorageFolder filesDirectory)
{
//code sample here
}
}
但现在我想让Dictionary 和该函数更通用,以使其接受两种不同类型的枚举,但我仍然不希望它接受超过这两种类型,有没有办法这么容易?
【问题讨论】:
-
因为 2 个枚举共享相同的底层值,您应该创建 2 个单独的字典,1 个用于 PosteComponent,1 个用于 LigneComponent。其他组合策略无法区分 LIEN 与 BT 等值
-
好吧,那是个坏消息
-
只用一个替换这两个枚举有意义吗?
-
不是那种情况,我在两个不同的类中使用这些枚举,它们专注于我的应用程序的两个不同部分