Morten Kruse

Morten Kruse

  • NA
  • 8
  • 1.3k

How to implement a generic method(pattern)?

Feb 10 2013 7:19 AM
Hi,

I have the following method

 public void ReadXmlFromFile(string path, string fileName)
        {          
            string filePath = Path.Combine(path, fileName);

            XmlSerializer deserializer = new XmlSerializer(TipsProvider.TipsList.GetType());
            TextReader textReader = null;

            try
            {
               textReader = new StreamReader(filePath);
               TipsProvider.TipsList = (List<Entity.Tips>)deserializer.Deserialize(textReader);     
            }
            catch(Exception e)
            { }
            finally
            { 
               if (textReader != null)
                    textReader.Close();
            }
        }


But now I want to use this method to also read xml from anothe typeof object.
The 3 bold lines is the objects that is "hard coded" in this method and should be generic.

How do i implement this?
Should i implement some kind of pattern?

Br Morten


Answers (1)