title: Save file - xmlSerializer
body: <p>I'm creating a method to serialize a file using this code:</p>
  
  <pre><code>public void Save(Object file, Type type, String path)
  {
      // Create a new Serializer
      XmlSerializer serializer = new XmlSerializer(typeof(type));
  
      // Create a new StreamWriter
      StreamWriter writer = new StreamWriter(@path);
  
      // Serialize the file
      serializer.Serialize(writer, file);
  
      // Close the writer
      writer.Close();
  }
  </code></pre>
  
  <p>But Visual Studio tells me this when I attempt to build:
  "Error  1   The type or namespace name 'type' could not be found (are you missing a using directive or an assembly reference?)  c:\users\erik\documents\visual studio 2013\Projects\FileSerializer\FileSerializer\Class1.cs 16  65  FileSerializer
  "</p>
  
  <p>Why is this?</p>
  
  <p>**EDIT*</p>
  
  <p>New code that works:</p>
  
  <pre><code>public void Save(Object file, String path, Type type)
  {
      // Create a new Serializer
      XmlSerializer serializer = new XmlSerializer(type);
  
      // Create a new StreamWriter
      TextWriter writer = new StreamWriter(path);
  
      // Serialize the file
      serializer.Serialize(writer, file);
  
      // Close the writer
      writer.Close();
  }
  
  public object Read(String path, Type type)
  {
      // Create a new serializer
      XmlSerializer serializer = new XmlSerializer(type);
  
      // Create a StreamReader
      TextReader reader = new StreamReader(path);
  
      // Deserialize the file
      Object file;
      file = (Object)serializer.Deserialize(reader);
  
      // Close the reader
      reader.Close();
  
      // Return the object
      return file;
  }
  </code></pre>
  
  <p>read by calling:</p>
  
  <pre><code>myClass newClass = (myClass)Read(file, type);
  </code></pre>
  
  <p>Save by calling:</p>
  
  <pre><code>Save(object, path, type);
  </code></pre>
  
  <p>Thanks!
  Erik</p>