static void GenerateMethodImpl (CodeClass c, MethodInfo processMethod, 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) Process (Contract.Operations [operName].SyncMethod, operName, parameters);
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)));
for (int i = 0; i < pinfos.Length; i++) {
ParameterInfo par = pinfos [i];
if (!par.IsOut)
b.Assign (
new CodeArrayItem (paramsRef, new CodeLiteral (i)),
new CodeCast (typeof (object),
new CodeArgumentReference (par.ParameterType, par.Position + 1, "arg" + i)));
}
#if USE_OD_REFERENCE_IN_PROXY
CodePropertyReference argMethodInfo = GetOperationMethod (m, b, name, "SyncMethod");
#else
CodeMethodCall argMethodInfo = new CodeMethodCall (typeof (MethodBase), "GetCurrentMethod");
#endif
CodeLiteral argOperName = new CodeLiteral (name);
CodeVariableReference retValue = null;
if (mi.ReturnType == typeof (void))
b.Call (m.GetThis (), processMethod, argMethodInfo, argOperName, paramsRef);
else {
CodeVariableDeclaration retValueDecl = new CodeVariableDeclaration (mi.ReturnType, "retValue");
b.CurrentBlock.Add (retValueDecl);
retValue = retValueDecl.Variable;
b.Assign (retValue,
new CodeCast (mi.ReturnType,
b.CallFunc (m.GetThis (), processMethod, argMethodInfo, argOperName, paramsRef)));
}
for (int i = 0; i < pinfos.Length; i++) {
ParameterInfo par = pinfos [i];
if (par.IsOut || par.ParameterType.IsByRef)
b.Assign (
new CodeArgumentReference (par.ParameterType, par.Position + 1, "arg" + i),
new CodeCast (par.ParameterType.GetElementType (),
new CodeArrayItem (paramsRef, new CodeLiteral (i))));
}
if (retValue != null)
b.Return (retValue);
}