public static ApiMethodBuilderInlineResult InlineConstant(TypeDescriptor typeDescriptor, string value, IStatement statement) { if (!typeDescriptor.IsString()) { throw new TypeMismatchCompilerException(typeDescriptor, TypeDescriptor.String, statement.Info); } return(Inline( new ConstantValueStatement(TypeDescriptor.String, string.IsNullOrWhiteSpace(BashTranspilerHelpers.GetString(value)) .ToString(NumberFormatInfo.InvariantInfo), statement.Info) )); }
public override string FormatConstantExpression(ExpressionBuilderParams p, TypeDescriptor typeDescriptor, string expression, EvaluationStatement template) { if (template is ConstantValueStatement constantValueStatement) { if (typeDescriptor.IsBoolean()) { if (!StatementHelpers.TryParseBooleanFromString(constantValueStatement.Value, out var boolResult)) { throw new InvalidStatementStructureCompilerException(template, template.Info); } return(boolResult ? "1" : "0"); } if (constantValueStatement.IsString() || constantValueStatement.IsDelegate()) { if (template.ParentStatement is ArithmeticEvaluationStatement arithmeticEvaluationStatement) { if (arithmeticEvaluationStatement.Operator is AdditionOperator) { if (p.FormatString) { return(BashTranspilerHelpers.ToBashString(constantValueStatement.Value, true, false)); } } else { throw new InvalidStatementStructureCompilerException(arithmeticEvaluationStatement, arithmeticEvaluationStatement.Info); } } return(base.FormatConstantExpression(p, typeDescriptor, expression, template)); } } return(base.FormatConstantExpression(p, typeDescriptor, expression, template)); }