コード例 #1
0
        private static bool TryHint(OperatorParams par, CsCodeWriter cw)
        {
            if (!(par.OperatorHints is null))
            {
                var builderInput = par.GetBuilder();
                if (!(builderInput is null))
                {
                    var builder = new OperatorCodeBuilder(builderInput);
                    cw.WriteLine("// scenario with hint");
                    builder.WriteCode(cw);
                    return(true);
                }
            }

            // Console.WriteLine("args.Input" + par.DebugIs);

            return(false);
        }
コード例 #2
0
        private static CsCodeWriter CreateCodeForLeftFractionValue(OperatorParams p,
                                                                   [NotNull] FractionUnit leftFraction)
        {
            if (leftFraction == null)
            {
                throw new ArgumentNullException(nameof(leftFraction));
            }

            var cw = Ext.Create <MultiplyAlgebraGenerator>();

            cw.WriteLine("// " + p);
            var canNormal = leftFraction.DenominatorUnit.Unit == p.Right.Unit &&
                            leftFraction.CounterUnit.Unit == p.Result.Unit;

            if (canNormal)
            {
                if (TryHint(p, cw))
                {
                    cw.WriteLine("// scenario D1");
                    return(cw);
                }
            }
            else
            {
                if (TryHint(p, cw))
                {
                    return(cw);
                }
                cw.WriteLine("// scenario D2");
                return(cw.WithThrowNotImplementedException());
            }

            var oper     = new OperatorCodeBuilderInput(p);
            var leftUnit = p.LeftMethodArgumentName + "Unit";

            oper.ConvertRight(leftUnit + ".DenominatorUnit");
            oper.ResultUnit = leftUnit + ".CounterUnit";
            oper.AddVariable(leftUnit, p.LeftMethodArgumentName + ".Unit");
            cw.WriteLine("// scenario D3");
            var builder = new OperatorCodeBuilder(oper);

            builder.WriteCode(cw);
            return(cw);
        }