Glen

Glen

  • NA
  • 1
  • 4.8k

Interface as parameter

Feb 16 2011 6:38 AM

Hi,
I am trying to create a method that needs to take an interface as a reference type.  Firstly is this even possible?
Basically my method needs to be called twice and the first param will be different types but both implement the interface, so I have something like this
 
private void validate(ref CMS.TreeEngine.TreeNode sku, DocTypeDefinition col, string productData)
{
   NewMethod(ref sku, col, productData);
}
private void validate(ref SKUInfo sku, DocTypeDefinition col, string productData)
{

   NewMethod(ref sku, col, productData);
}
private static void NewMethod(ISimpleDataContainer sku, DocTypeDefinition col, string productData)
{
switch (col.ColumnType)
{
   case "integer":
   sku.SetValue(col.ColumnID,
ValidationHelper.GetInteger(productData, 0));
   break;
}
}

So you can see that the first param in validate is of different types but both methods call the new method, whose first param is an interface.
This approach does not work it throws a complier error.
Can anyone point me in the right direction please?
Thanks

Answers (2)