Enum형식인 Actor와 Language를 키로 가지고 name을 값으로 가지는 이름을 가져오는 클래스를 생성했다.
하지만 내부 초기화가 안 되어서 고민했다.
public static class ActorNameDict
{
public static Dictionary<EActor, Dictionary<ELanguage, string>> ActorDict = new Dictionary<EActor, Dictionary<ELanguage, string>>()
{
{EActor.Gayoit, GayoitNameDict },
{EActor.Devil1, Devil1NameDict },
{EActor.Devil2, Devil2NameDict },
{EActor.EvilWizard, EvilWizardNameDict },
{EActor.NightSword, NightSwordNameDict },
};
public static Dictionary<ELanguage, string> GayoitNameDict = new Dictionary<ELanguage, string>()
{
{ELanguage.Korean, "가요잇" },
{ELanguage.English, "Gayoit" },
};
이런식으로 작성을 했는데, static dictionary Actordict가 초기화가 안 되는 상황이였다.
찾아보니 static class내부의 static dictionary를 생성자를 이용해 초기화를 시켜줘야한다는 글을 봤다.
public static class ActorNameDict
{
public static Dictionary<EActor, Dictionary<ELanguage, string>> ActorDict;
static ActorNameDict()
{
ActorDict = new Dictionary<EActor, Dictionary<ELanguage, string>>()
{
{EActor.Gayoit, GayoitNameDict },
{EActor.Devil1, Devil1NameDict },
{EActor.Devil2, Devil2NameDict },
{EActor.EvilWizard, EvilWizardNameDict },
{EActor.NightSword, NightSwordNameDict },
{EActor.Elf, ElfNameDict },
{EActor.Ninja, NinjaNameDict },
{EActor.IceWizard, IceWizardNameDict },
{EActor.Granny, GrannyNameDict },
};
}
public static Dictionary<ELanguage, string> GayoitNameDict = new Dictionary<ELanguage, string>()
{
{ELanguage.Korean, "가요잇" },
{ELanguage.English, "Gayoit" },
};
이런식으로 static생성자를 통해 초기화를 했더니 정상적으로 잘 작동한다.