Hey I'm new to Spec# and don't even get the very basics...
I'm trying to make a fileloader class which shouldn't be created if the filename is wrong.
I made the following (try 1) but get this error about "delayed arguments not matching non-delayed parameters"
The tried to do something about it (try 2), but gets an error about "missing object reference to 'file' "
I'm lost. If anyone could help me out I'll be very happy
Thanks in Advance
Mygind
############## TRY 1 ###############
using System;
using System.IO;
public class FileLoader
{
FileStream file;
StreamReader !stream;
invariant file != null;
public FileLoader(String filename)
{
file = new FileStream(filename, FileMode.Open, FileAccess.Read);
if(file == null){
throw(new MissingFileException("File doesn't exist!"));
}
stream = new StreamReader(file);
}
public string readLine()
{
return stream.ReadLine();
}
~FileLoader()
{
file.Close();
}
}
######## TRY 2 #################
[Microsoft.Contracts.NotDelayed]
public FileLoader(String filename)
{
try{
file = new FileStream(filename, FileMode.Open, FileAccess.Read);
} catch(Exception e){
throw new MissingFileException("File doesn't exist!");
}
if(file == null){
throw(new MissingFileException("File doesn't exist!"));
}
stream = new StreamReader(file);
base();
}