/// <summary> /// Creates a writer for the specified method. /// </summary> private static Expression <Action <object[], IThriftProtocol> > CreateWriterForMethod(ThriftMethod method) { var argsParam = Expression.Parameter(typeof(object[])); var protocolParam = Expression.Parameter(typeof(IThriftProtocol)); var methodContents = new List <Expression> { Expression.Call( protocolParam, Methods.IThriftProtocol_WriteMessageHeader, Expression.New( Constructors.ThriftMessageHeader, Expression.Constant(method.Name), Expression.Constant(method.IsOneWay ? ThriftMessageType.OneWay : ThriftMessageType.Call) ) ), Expression.Call( protocolParam, Methods.IThriftProtocol_WriteStructHeader, Expression.New( Constructors.ThriftStructHeader, Expression.Constant("") ) ) }; for (int n = 0; n < method.Parameters.Count; n++) { var wireField = ThriftWireField.Parameter(method.Parameters[n], argsParam, n); methodContents.Add(ThriftStructWriter.CreateWriterForField(protocolParam, wireField)); } methodContents.Add(Expression.Call(protocolParam, Methods.IThriftProtocol_WriteFieldStop)); methodContents.Add(Expression.Call(protocolParam, Methods.IThriftProtocol_WriteStructEnd)); methodContents.Add(Expression.Call(protocolParam, Methods.IThriftProtocol_WriteMessageEnd)); return(Expression.Lambda <Action <object[], IThriftProtocol> >( Expression.Block(methodContents), argsParam, protocolParam )); }