Exemplo n.º 1
0
        private void CreateClassNodes(ClassesContainer container, CharacterClass characterClass, IEnumerable <IBuild> builds)
        {
            IBuild[] unserializedBuilds = builds as IBuild[] ?? builds.ToArray();
            Build[]  serializedBuilds   = new Build[unserializedBuilds.Length];
            for (int i = 0; i < unserializedBuilds.Length; i++)
            {
                serializedBuilds[i] = CreateBuildNodes(unserializedBuilds[i]);
            }
            switch (characterClass)
            {
            case CharacterClass.Barbarian:
                container.Barbarian.Build = serializedBuilds;
                break;

            case CharacterClass.Crusader:
                container.Crusader.Build = serializedBuilds;
                break;

            case CharacterClass.DemonHunter:
                container.DemonHunter.Build = serializedBuilds;
                break;

            case CharacterClass.Monk:
                container.Monk.Build = serializedBuilds;
                break;

            case CharacterClass.WitchDoctor:
                container.WitchDoctor.Build = serializedBuilds;
                break;

            case CharacterClass.Wizard:
                container.Wizard.Build = serializedBuilds;
                break;

            default:
                throw new ArgumentOutOfRangeException("characterClass", characterClass, null);
            }
        }
Exemplo n.º 2
0
        public void Serialize(IDictionary <CharacterClass, IEnumerable <IBuild> > builds, string filePath)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ClassesContainer));
            TextWriter    writer     = new StreamWriter(filePath, false);

            ClassesContainer cc = new ClassesContainer();

            cc.Barbarian   = new BuildContainer();
            cc.Crusader    = new BuildContainer();
            cc.DemonHunter = new BuildContainer();
            cc.Monk        = new BuildContainer();
            cc.WitchDoctor = new BuildContainer();
            cc.Wizard      = new BuildContainer();

            foreach (CharacterClass characterClass in Enum.GetValues(typeof(CharacterClass)))
            {
                if (builds.ContainsKey(characterClass))
                {
                    CreateClassNodes(cc, characterClass, builds[characterClass]);
                }
            }
            serializer.Serialize(writer, cc);
            writer.Close();
        }