public ICommand ToCommand(Object serial, Stream stream, Encoding encoding) { if (stream == null) { return(default(ICommand)); } CommandIdentifier identifier = null; if (Identities != null && Identities.ContainsKey(serial)) { identifier = (CommandIdentifier)Identities [serial]; } if (identifier == null) { return(default(ICommand)); } Object command = null; // create a reader, using the specific encoding of the socket using (StreamReader reader = new StreamReader(stream, encoding)) { //XmlDocument xmldoc = new XmlDocument(); //xmldoc.Load (reader); // create a serializer for the given object type. XmlSerializer serializer = new XmlSerializer(identifier.CommandType); //XmlWriterSettings settings = new XmlWriterSettings(); //settings.Encoding = encoding; //settings.Indent = false; //XmlReader reader = XmlReader.Create(stream, settings); command = serializer.Deserialize(reader); //xmldoc. /* * using (XmlReader xmlr = XmlReader.Create(reader)) { * XmlDocument xml = new XmlDocument(); * * } */ // // serializer lock, making it thread safe. // lock (SerializerLock) { // c = Serializer.Deserialize(reader); // reader.Close(); // } } if (!(command is ICommand)) { // TODO throw exception return(default(ICommand)); } return((ICommand)command); }