public BinaryOperands Validate(string commaSeparatedOperands) { //empty input string is converted to 0 if (string.IsNullOrEmpty(commaSeparatedOperands)) { return(new BinaryOperands { Operand1 = 0, Operand2 = 0 }); } var operands = commaSeparatedOperands.Split(new char[] { ',', '\n' }); if (operands.Length > 2) { throw new NotBinaryOperandException(); } if (operands.Length == 1) { return(new BinaryOperands { Operand1 = operands[0].ToIntOperand(), Operand2 = 0 }); } if (operands.Length == 2) { BinaryOperands ret = new BinaryOperands { Operand1 = 0, Operand2 = 0 }; ret.Operand1 = operands[0].ToIntOperand(); ret.Operand2 = operands[1].ToIntOperand(); return(ret); } throw new ArgumentException(); }
public async override Task <UnaryResult> Add(BinaryOperands request, ServerCallContext context) { await Task.CompletedTask; return(new UnaryResult { Result = request.Operand1 + request.Operand2 }); }