Exemple #1
0
        private static void HandleCreateOperatorCode(object sender, OperatorHints.CreateOperatorCodeEventArgs e)
        {
            if (!e.ShouldITryToCreate(nameof(Def_Power_Length_LinearPowerLoss)))
            {
                return;
            }
            e.Result.Comment = e.Input.DebugIs;
            var input  = e.Input;
            var result = e.Result;

            if (input.Is <UnitA, UnitB, UnitC>("/"))
            {
                e.SetHandled();
                result.SetComment();
                result.Comment   += " " + nameof(Def_Power_Length_LinearPowerLoss);
                result.ResultUnit = $"new {ValueC}Unit({ValueA.FirstLower()}.Unit, {ValueB.FirstLower()}.Unit)";
                return;
            }

            if (input.Is <UnitC, UnitB, UnitA>("*"))
            {
                e.SetHandled();
                result.SetComment();
                result.Comment += " " + nameof(Def_Power_Length_LinearPowerLoss);
                result.ConvertRight($"{ValueC.FirstLower()}.Unit.DenominatorUnit");
                result.ResultUnit = $"{ValueC.FirstLower()}.Unit.CounterUnit";
            }
        }
        private static void HandleCreateOperatorCode(object sender, OperatorHints.CreateOperatorCodeEventArgs e)
        {
            if (!e.ShouldITryToCreate(nameof(Def_LinearPowerLoss_Length_Irradiance)))
            {
                return;
            }
            e.Result.Comment = e.Input.DebugIs;
            var input  = e.Input;
            var result = e.Result;

            if (input.Is <UnitA, UnitB, UnitC>("/"))
            {
                e.SetHandled();
                result.SetComment();

                result.AddVariable("lengthUnit", "linearPowerLoss.Unit.DenominatorUnit");
                result.AddVariable("areaUnit", "lengthUnit.GetAreaUnit()");
                result.AddVariable("powerUnit", $"{ValueA.FirstLower()}.Unit.CounterUnit");

                result.Comment += " " + nameof(Def_LinearPowerLoss_Length_Irradiance);
                result.ConvertRight("lengthUnit");
                result.WithResultUnit <UnitCUnit>("powerUnit", "areaUnit");
                return;
            }

            if (input.Is <UnitA, UnitC, UnitB>("/"))
            {
                e.SetHandled();
                result.SetComment();
                result.AddVariable("resultUnit", "linearPowerLoss.Unit.DenominatorUnit");
                result.AddVariable("areaUnit", "resultUnit.GetAreaUnit()");
                // result.AddVariable<IrradianceUnit>("irradianceUnit", "irradiance.Unit.CounterUnit", "areaUnit");
                result.Comment += " " + nameof(Def_LinearPowerLoss_Length_Irradiance);

                result.ConvertRight_WithDenominatorUnit("areaUnit");

                result.ResultUnit = "resultUnit";
                return;
            }



            if (input.Is <UnitC, UnitB, UnitA>("*"))
            {
                e.SetHandled();
                result.SetComment();
                result.Comment += " " + nameof(Def_LinearPowerLoss_Length_Irradiance);
                result.ConvertRight($"{ValueC.FirstLower()}.Unit.DenominatorUnit.GetLengthUnit()");
                result.WithResultUnit <LinearPowerLossUnit>("irradiance.Unit.CounterUnit", "lengthConverted.Unit");
            }


            if (input.Is <UnitB, UnitC, UnitA>("*"))
            {
                e.SetHandled();
                result.SetComment();
                result.Comment += " " + nameof(Def_LinearPowerLoss_Length_Irradiance);
                result.AddVariable("areaUnit", "length.Unit.GetAreaUnit()");
                result.ConvertRight_WithDenominatorUnit("areaUnit");
                result.WithResultUnit <LinearPowerLossUnit>($"{ValueC.FirstLower()}.Unit.CounterUnit", $"{ValueB.FirstLower()}.Unit");
            }
        }