void ReadContent(string path)
{
Contract.Requires(path!=null);
string contentofileasstring = filehelperobj.GetContent(path);
if(String.IsNullOrEmpty(contentofileasstring ))
{
throw new FileContentException(path + "No content found");
}
m_xmlobj = contentofileasstring ;
}
Is my assumption of the usage of code contracts and exceptions right in this case. Do you think it is logical to replace the exception with a code contract(or vice versa)?
code not tested.Just an example scenario
I would probably go for an implementation which looks like the following:
Post Edit
As it’s the content you want to validate, I would put a
Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<string>()));inside thefilehelperobj.GetContent(string)method. Then if the content being read was null or empty, I would throw an exception. e.g.