예제 #1
0
    //Como dice, lee objetos serializados gge segun lo que encuentra en core.xml
    //IGenericGameElement gge es el objeto en donde se va a guardar el deserializado, ggeType el tipo de objeto (carta, token)
    public IGenericGameElement ReadSerialized(IGenericGameElement gge, string path, string ggeType)
    {
        string ggePath = path +"app/"+this.ggeName+".xml";
        //Reflection
        Type unknowType = Type.GetType (ggeType);

        XmlSerializer serializer = new XmlSerializer(unknowType);
        FileStream stream = new FileStream(ggePath, FileMode.Open);
        Debug.Log("Hurray gge XML cargado");

        try{
            gge = serializer.Deserialize(stream) as IGenericGameElement;
        }catch(Exception e){
            Debug.Log("Invalid XML");
            Debug.Log(e);
        }
        finally{stream.Close();}
        return gge;
    }
        //METODOS
        public IGenericGameElement ReadSerialized(IGenericGameElement gge, string path, string type)
        {
            GGEFactory fac = new GGEFactory();
            //GGECard card = new GGECard();
            IGenericGameElement ggeUnknow;
            path = "C:\\loveLetter";
            string ggePath = path + "\\app\\" + this.ggeName + ".xml";

            //Reflection get type
            Type MyType = Type.GetType("ConsoleApplication1."+type);

            XmlSerializer serializer = new XmlSerializer(MyType);
            FileStream stream = new FileStream(ggePath, FileMode.Open);
            Console.WriteLine("Hurray gge XML cargado");

            try
            {
                ggeUnknow = serializer.Deserialize(stream) as IGenericGameElement;
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid XML");
                Console.WriteLine(e);
                ggeUnknow = fac.CreateInstance("GGECard");
            }
            finally { stream.Close(); }
            return ggeUnknow;
        }