Home > Net >  Is there a cleaner way to map an object to a class (e.g. using a dictionary)?
Is there a cleaner way to map an object to a class (e.g. using a dictionary)?

Time:02-10

public static class SceneToGame{
    public static GameParentServer Server(int scene, Server server){
        switch (scene){
            case 1:
                return new SnapGameServer(server);
            default:
                return null;
        }
    }
}

I'm currently using this to map ints to classes with a common parent. Is there a cleaner way to do this? From what I've read you can't because C# is type safe despite this being type safe.

CodePudding user response:

  •  Tags:  
  • Related