Avro.CodeGen.AvroGen.createProtocolClient C# (CSharp) Метод

createProtocolClient() приватный Метод

private createProtocolClient ( Protocol protocol, CodeNamespace ns, CodeTypeReference protocolInterface ) : void
protocol Protocol
ns System.CodeDom.CodeNamespace
protocolInterface System.CodeDom.CodeTypeReference
Результат void
        private void createProtocolClient(Protocol protocol, CodeNamespace ns, CodeTypeReference protocolInterface)
        {
            string clientName = string.Concat(protocol.Name, "Client");
            CodeTypeDeclaration typeClient = createCodeTypeDeclaration(clientName);
            typeClient.IsClass = true;
            typeClient.IsPartial = true;
            typeClient.Attributes = MemberAttributes.Public;
            typeClient.BaseTypes.Add(new CodeTypeReference(typeof(Avro.RPC.RPCClient)));
            typeClient.BaseTypes.Add(protocolInterface);
            ns.Types.Add(typeClient);

            foreach (Message message in protocol.Messages)
            {
                CodeMemberMethod methodMessage = new CodeMemberMethod();
                typeClient.Members.Add(methodMessage);
                methodMessage.Name = message.Name;
                methodMessage.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                if (!(message.Response == null||message.Response == PrimitiveSchema.NULL))
                    methodMessage.ReturnType = getCodeTypeReference(message.Response);
                if (!string.IsNullOrEmpty(message.Doc))
                    methodMessage.Comments.Add(createDocComment(message.Doc));

                List<CodeExpression> invokeParameters = new List<CodeExpression>();
                invokeParameters.Add(new CodePrimitiveExpression(message.Name));
                invokeParameters.Add(new CodePrimitiveExpression(null));
                foreach (Message.Parameter messageParm in message.Request)
                {
                    CodeVariableReferenceExpression varParm = new CodeVariableReferenceExpression(messageParm.Name);
                    CodeTypeReference messageTypeRef = getCodeTypeReference(messageParm.Schema);
                    CodeParameterDeclarationExpression decParm = new CodeParameterDeclarationExpression(messageTypeRef, messageParm.Name);
                    methodMessage.Parameters.Add(decParm);

                    CodeTypeReference refParameter = new CodeTypeReference(typeof(Avro.RPC.Parameter<>));
                    refParameter.TypeArguments.Add(messageTypeRef);

                    CodeObjectCreateExpression createparm = new CodeObjectCreateExpression(refParameter, new CodePrimitiveExpression(null), varParm);
                    invokeParameters.Add(createparm);
                }

                CodeMethodInvokeExpression callInvoke = new CodeMethodInvokeExpression(new CodeBaseReferenceExpression(), "Invoke", invokeParameters.ToArray());

                if ((message.Response == null || PrimitiveSchema.NULL.Equals(message.Response)))
                {
                    methodMessage.Statements.Add(callInvoke);
                }
                else
                {
                    callInvoke.Method.TypeArguments.Add(methodMessage.ReturnType);
                    methodMessage.Statements.Add(new CodeMethodReturnStatement(callInvoke));
                    
                }




                methodMessage.Statements.Add(new CodeThrowExceptionStatement( new CodeObjectCreateExpression( typeof(NotImplementedException))));

            }
        }