Beispiel #1
0
        public static CsMethod AddOperator(this CsClass cl, string operatorName, CsArguments csArgument, string resultType = null)
        {
            resultType = resultType.CoalesceNullOrWhiteSpace(cl.Name);
            var code = csArgument.Create(resultType);

            return(cl.AddMethod(operatorName, resultType, "implements " + operatorName + " operator")
                   .WithBodyFromExpression(code));
        }
        private static CsCodeWriter CreateCodeForFractionalResult(OperatorParams p)
        {
            var cw = Ext.Create <MultiplyAlgebraGenerator>();

            cw.WriteLine("// scenario E");
            var args = new CsArguments(
                $"{p.LeftMethodArgumentName}.Value {p.Oper} {p.RightMethodArgumentName}.Value",
                $"{p.LeftMethodArgumentName}.Unit",
                $"{p.RightMethodArgumentName}.Unit"
                );
            var tResult = p.Result.Value;

            var expression = args.Create(tResult.ValueTypeName);

            cw.WriteLine($"return {expression};");
            return(cw);
        }