Esempio n. 1
0
        private static void Add_EnergyMassDensity_DeltaKelvinTemperature_SpecificHeatCapacity(MultiplicationAlgebra c)
        {
            var hints = new OperatorHints();

            hints.CreateOperatorCode += (sender, args) =>
            {
                args.Result.Comment = args.Input.DebugIs;
                AlgebraDefUtils.CreateHeuristicCode(args);
                args.SetHandled();
            };
            hints.ImplementingClass = nameof(MultiplicationAlgebraDefs);

            c.WithDiv <EnergyMassDensity, DeltaKelvinTemperature, SpecificHeatCapacity>(hints);
        }
Esempio n. 2
0
        private static void HandleCreateOperatorCode(object sender, OperatorHints.CreateOperatorCodeEventArgs args)
        {
            if (!args.ShouldITryToCreate(nameof(Def_Energy_Time_Power)))
            {
                return;
            }
            var input  = args.Input;
            var result = args.Result;

            result.Comment = args.Input.DebugIs;

            if (input.Is <Energy, Power, Time>("/"))
            {
                args.SetHandled();
                AlgebraDefUtils.Add1(result, "timeSeconds");
                result.AddVariable("returnType", "energy.Unit.GetSuggestedTimeUnit()");
                result.AddVariable("time", "Time.FromSecond(timeSeconds).ConvertTo(returnType)");
                result.UseReturnExpression = "time";
                return;
            }

            if (input.Is <Energy, Time, Power>("/"))
            {
                args.SetHandled();
                AlgebraDefUtils.CreateHeuristicCode(args);
                return;
            }

            if (input.Is <Time, Power, Energy>("*"))
            {
                args.SetHandled();
                AlgebraDefUtils.Add1(result, "basicEnergy");
                result.UseValueExpression = "basicEnergy";
                result.ResultUnit         = "EnergyUnits.Joule";
                return;
            }

            if (input.Is <Power, Time, Energy>("*"))
            {
                args.SetHandled();
                result.AddVariable("x", "4");
                AlgebraDefUtils.Add1(result, "basicEnergy");
                result.UseValueExpression = "basicEnergy";
                result.ResultUnit         = "EnergyUnits.Joule";
                return;
            }
        }