What is the best way of supporting optional data passed to a C# function?
I have web service function in .Net which defines 5 arguments:
[WebMethod]
public string UploadFile( string wsURL
, byte[] incomingArray
, string FileName
, string RecordTypeName
, MetaData[] metaDataArray)
The code of this function is not too long (but not trivial either) and there is only one place in the the function where I perform this test if there is any MetaData[] to be processed:
if (metaDataArray.Length > 0)
{
Update update = BuildMetaData(metaDataArray);
treq2.Items = new Operation[] { sru, cin, update, fetch};
}
else
{
treq2.Items = new Operation[] { sru, cin, fetch};
}
I needed a quick and dirty version of the above which only takes 4 arguments (i.e. no "Metadata" array as a final argument) so I cloned the whole function and removed the IF-ELSE block refering to metadata. Ugly I know.
[WebMethod]
public string UploadFileBasic( string wsURL
, byte[] incomingArray
, string FileName
, string RecordTypeName)
Now I want to do things better and I am looking for advice on the best way to support this. I do not want to burden the client program with creating an empty array as a 5th parameter...I want to have my web service functions to be smart enough to handle this optional data. Thanks.