/// <inheritdoc /> protected override int ParseLiteral(IntValueNode valueSyntax) { if (valueSyntax.ToInt32() > MaxValue) { throw ThrowHelper.NegativeIntType_ParseLiteral_IsNotNegative(this); } return(base.ParseLiteral(valueSyntax)); }
internal static StreamDirective?GetStreamDirective( this IReadOnlyList <DirectiveNode> directives, IVariableValueCollection variables) { DirectiveNode?directiveNode = GetDirective(directives, WellKnownDirectives.Stream); if (directiveNode is not null) { var @if = true; string?label = null; var initialCount = 0; foreach (ArgumentNode argument in directiveNode.Arguments) { switch (argument.Name.Value) { case WellKnownDirectives.IfArgument: @if = argument.Value switch { VariableNode variable => variables.GetVariable <bool>(variable.Name.Value), BooleanValueNode b => b.Value, _ => @if }; break; case WellKnownDirectives.LabelArgument: label = argument.Value switch { VariableNode variable => variables.GetVariable <string?>(variable.Name.Value), StringValueNode b => b.Value, _ => label }; break; case WellKnownDirectives.InitialCount: initialCount = argument.Value switch { VariableNode variable => variables.GetVariable <int>(variable.Name.Value), IntValueNode b => b.ToInt32(), _ => initialCount }; break; } } return(new StreamDirective(@if, initialCount, label)); } return(null); }
/// <inheritdoc /> protected override TRuntimeType ParseLiteral(IntValueNode literal) { if (TryDeserialize(literal.ToInt32(), out TRuntimeType? value)) { return(value.Value); } throw new SerializationException( string.Format(IntToStructBaseType_ParseLiteral_UnableToDeserializeInt, Name), this); }
protected override TRuntimeType ParseLiteral(IntValueNode literal) { if (TryDeserialize(literal.ToInt32(), out TRuntimeType? value)) { return(value.Value); } throw new SerializationException( $"Unable to deserialize integer to {this.Name}", this); }
public void ParseLiteral_IntLiteral() { // arrange var type = new IntType(); var literal = new IntValueNode(1); // act var value = type.ParseLiteral(literal); // assert Assert.IsType <int>(value); Assert.Equal(literal.ToInt32(), value); }
/// <inheritdoc /> protected override bool IsInstanceOfType(IntValueNode valueSyntax) { return(valueSyntax.ToInt32() <= MaxValue); }
protected override int ParseLiteral(IntValueNode valueSyntax) { return(valueSyntax.ToInt32()); }
protected override int ParseLiteral(IntValueNode valueSyntax) => valueSyntax.ToInt32();
protected override int ParseLiteral(IntValueNode literal) { return(literal.ToInt32()); }