static void GenerateBeginMethodImpl (CodeClass c, MethodInfo beginProcessMethod, string name, MethodInfo mi)
{
CodeMethod m = c.ImplementMethod (mi);
CodeBuilder b = m.CodeBuilder;
// object [] parameters = new object [x];
// parameters [0] = arg1;
// parameters [1] = arg2;
// ...
// (return) BeginProcess (Contract.Operations [operName].BeginMethod, operName, parameters, asyncCallback, userState);
ParameterInfo [] pinfos = mi.GetParameters ();
CodeVariableDeclaration paramsDecl = new CodeVariableDeclaration (typeof (object []), "parameters");
b.CurrentBlock.Add (paramsDecl);
CodeVariableReference paramsRef = paramsDecl.Variable;
b.Assign (paramsRef,
new CodeNewArray (typeof (object), new CodeLiteral (pinfos.Length - 2)));
for (int i = 0; i < pinfos.Length - 2; i++) {
ParameterInfo par = pinfos [i];
if (!par.IsOut)
b.Assign (
new CodeArrayItem (paramsRef, new CodeLiteral (i)),
new CodeCast (typeof (object), m.GetArg (i)));
}
#if USE_OD_REFERENCE_IN_PROXY
CodePropertyReference argMethodInfo = GetOperationMethod (m, b, name, "BeginMethod");
#else
CodeMethodCall argMethodInfo = new CodeMethodCall (typeof (MethodBase), "GetCurrentMethod");
#endif
CodeLiteral argOperName = new CodeLiteral (name);
ParameterInfo p = pinfos [pinfos.Length - 2];
CodeArgumentReference callbackRef = new CodeArgumentReference (typeof (AsyncCallback), p.Position + 1, p.Name);
p = pinfos [pinfos.Length - 1];
CodeArgumentReference stateRef = new CodeArgumentReference (typeof (object), p.Position + 1, p.Name);
CodeVariableDeclaration retValueDecl = new CodeVariableDeclaration (mi.ReturnType, "retValue");
b.CurrentBlock.Add (retValueDecl);
CodeVariableReference retValue = retValueDecl.Variable;
b.Assign (retValue,
new CodeCast (mi.ReturnType,
b.CallFunc (m.GetThis (), beginProcessMethod, argMethodInfo, argOperName, paramsRef, callbackRef, stateRef)));
b.Return (retValue);
}