I have this code that I wrote but I am getting an error saying that a namespace cannot include methods. Would appreciate any advice on what I am doing wrong and / or a suggestion on how I could code this in a better way to avoid this error.
namespace WriteToExcel
{
class Program
{
static void Main(string[] args)
{
List<PhraseSource> data = ReadFromFile();
}
static List<PhraseSource ReadFromFile()
{
var filepath = @"/Users/psnet.data";
return ReadFromJsonFile<List<PhraseSource>>(filepath);
}
static T ReadFromJsonFile<T>(string filePath) where T : new()
{
TextReader reader = null;
try
{
reader = new StreamReader(filePath);
var fileContents = reader.ReadToEnd();
return JsonConvert.DeserializeObject<T>(fileContents);
}
finally
{
if (reader != null)
reader.Close();
}
}
}
}
