public override void GenerateReadFunctionBody(ICodeWriter read) { read.GeneratedByComment() .Append(@" if( r.TokenType != System.Text.Json.JsonTokenType.String ) throw new System.Text.Json.JsonException( $""BigInt input type must be string. Token is '{r.TokenType}'."" ); var s = r.GetString(); r.Read(); if( Int64.TryParse( s, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out var l ) ) { return l; } if( UInt64.TryParse( s, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out var ul ) ) { return ul; } if( Decimal.TryParse( s, out var d ) ) { return d; } if( System.Numerics.BigInteger.TryParse( s, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out var b ) ) { return b; } throw new System.IO.InvalidDataException( ""BigInt input type is invalid. Cannot parse a long, ulong, decimal or BigInteger from: "" + s );"); }
public override void GenerateReadFunctionBody(ICodeWriter read) { read.GeneratedByComment() .Append(@" // Postel's law: accepting (useless) string. double d = r.TokenType == System.Text.Json.JsonTokenType.String ? double.Parse( r.GetString(), System.Globalization.NumberFormatInfo.InvariantInfo ) : r.GetDouble(); r.Read(); return d;"); }
public void WriteDeclarations(ICodeWriter declSpace) { declSpace.GeneratedByComment(); foreach (var(t, (idx, opt)) in _mapping) { if (idx != 1) { declSpace.Append("var s").Append(idx) .Append(" = scope.ServiceProvider.GetService<").AppendCSharpName(t, true, true, true).Append(">( ").Append(!opt).Append(" );").NewLine(); } } foreach (var(name, def) in _parametersArray) { declSpace.Append("var ").Append(name).Append(" = new object[]{ ").Append(def).Append(" };").NewLine(); } }