I have defined an Interface in an attempt to make things behave the same way
interface IinFileMetaHandler
{
public int GetProperty (string fileName, string propertyName, string propertyValue, string fileType);
public int SetProperty (string fileName, string propertyName, string propertyValue, string fileType);
}
The use case is reading and writing metadata into files of different types.
Initially there is one for ‘image’ files (jpg, tiff etc) and one for openxml office documents (docx, xlsx etc)
Thus there are 2 real things descending from this interface
class InterfaceModule_exiftool : IinFileMetaHandler
class InterfaceModule_openxml : IinFileMetaHandler
and obviously they have the same methods as the interface
Question: is there a way to instantiate these things so that all the real work doesn’t care what flavour it is.
ie be able to issue 'myInterface.GetProperty (pFileName , xtargetAttribute, propertyValue, fileType);'
and it knows which path to take because of how they were constructed
I tried the following but (not supprisingly) it gives me ‘CS0128: A local variable or function named ‘myInterface’ is already defined in this scope’
I thought I would ask before I spent hours trying to define a generic object before the switch statement.
switch(xInterface)
{
case "exiftool":
var myInterface = new InterfaceModule_exiftool(s_exifTool);
break;
case "openxml":
var myInterface = new InterfaceModule_openxml();
break;
default:
Logger.Error($"Error! No code module known to handle '{xInterface}'. Check XML" );
return 4;
}
int rc = myInterface.GetProperty (pFileName , xtargetAttribute, propertyValue, fileType);
Console.WriteLine($" ===> propertyValue= {propertyValue} ");
Thanks,
JC