使用多个对象传递参数

时间:2013-04-18 17:27:15

标签: list object parameter-passing

所以我想做的是传入一个对象列表,但我有很多不同的。 (剑,胸甲等)。如何将多个对象传递给参数?

ListToSave = testObject.ChestPlateList;下面的部分是我要将对象列表传递给的部分。

public void DeserializeFromXML(List<ChestPlate> ListToSave, string filepath)
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(GameObjectData));
            FileStream fs = new FileStream(filepath, FileMode.Open);
            XmlReader reader = new XmlTextReader(fs);

            if (!reader.EOF)
            {
                GameObjectData testObject = (GameObjectData)deserializer.Deserialize(reader);
                ListToSave = testObject.ChestPlateList;
                Console.WriteLine("{0}", testObject.ChestPlateList);             
            }        
        }

1 个答案:

答案 0 :(得分:0)

试试这个(未经测试的)

public void SerializeToXML(GameObjectData theData, string filepath)
{
    XmlSerializer serializer = new XmlSerializer(typeof(theData));
    TextWriter writer = new StreamWriter(filepath);
    serializer.Serialize(writer, ListToSave);
}

public GameObjectData DeserializeFromXML(string filepath)
{
    GameObjectData result = null;
    XmlSerializer deserializer = new XmlSerializer(typeof(GameObjectData));
    FileStream fs = new FileStream(filepath, FileMode.Open);
    XmlReader reader = new XmlTextReader(fs);

    if (!reader.EOF)
    {
        result = (List<GameObject>)deserializer.Deserialize(reader);

        Console.WriteLine("{0}", result.ChestPlateList);              
    }   
    return result;     
}