protected override void Add_GetBaseUnitValue() { var cs = Ext.Create <BasicUnitValuesGenerator>(); cs.WriteLine("var factor1 = GlobalUnitRegistry.Factors.Get(Unit.LeftUnit);"); cs.WriteLine("var factor2 = GlobalUnitRegistry.Factors.Get(Unit.RightUnit);"); cs.SingleLineIf("(factor1.HasValue && factor2.HasValue)", ReturnValue("Value * factor1.Value * factor2.Value")); var exceptionMessage = new CsExpression("Unable to find multiplication for unit ".CsEncode()) + new CsExpression("Unit"); cs.Throw <Exception>(exceptionMessage.ToString()); Target.AddMethod("GetBaseUnitValue", ValuePropertyType) .WithBody(cs); }
protected virtual void Add_GetBaseUnitValue() { var cs = Ext.Create <BasicUnitValuesGenerator>(); cs.SingleLineIf("Unit.Equals(BaseUnit)", ReturnValue("Value")); cs.WriteLine("var factor = GlobalUnitRegistry.Factors.Get(Unit);"); cs.SingleLineIf("!(factor is null)", ReturnValue("Value * factor.Value")); var exceptionMessage = new CsExpression("Unable to find multiplication for unit ".CsEncode()) + new CsExpression("Unit"); cs.Throw <Exception>(exceptionMessage.ToString()); Target.AddMethod("GetBaseUnitValue", ValuePropertyType) .WithBody(cs); }