I am consuming a web service which has a number of methods (50) which create different objects.
example:
CreateObject1(Object1 obj, int arg2)
CreateObject2(Object2 obj, int arg2)
...
CreateObjectX(ObjectX obj, int arg2)
All Objects (Object1, Object2, ObjectX...) inherit from ObjectBase.
So I am trying to do this...
delegate void DlgtCreateObject(ObjectBase obj, int arg2);
public void CreateObject(ObjectBase obj, int arg2)
{
DlgtCreateObject dlgt;
string objType;
string operation;
objType = obj.GetType().ToString();
operation = "Create" + objType.Substring(objType.LastIndexOf(".") + 1);
using (MyWebService service = new MyWebService())
{
dlgt = (DlgtCreateObject)Delegate.CreateDelegate(typeof(DlgtCreateObject),
service,
operation,
false,
true);
dlgt(obj, arg2);
}
}
Unfortunately this gives me a Failed to Bind exception. I believe this is because my delegate signature uses the ObjectBase as its first argument where the functions use the specific classes.
Is there a way around this?