private AnnotationExpression(AnnotationExpressionKind kind, object value, Position position = default) { CheckValueType(kind, value); Kind = kind; Value = value; Position = position; }
private static void CheckValueType(AnnotationExpressionKind kind, object value) { if (value == null) { if (kind == AnnotationExpressionKind.Null) { return; } System.Diagnostics.Debug.Fail($"wrong value 'null' for Expression kind '{kind}' "); } var type = value.GetType(); switch (kind) { case AnnotationExpressionKind.Array: if (typeof(IReadOnlyCollection <AnnotationExpression>).IsAssignableFrom(type)) { return; } break; case AnnotationExpressionKind.Object: if (typeof(IReadOnlyCollection <ExpressionProperty>).IsAssignableFrom(type)) { return; } break; default: if (_kinds.TryGetValue(kind, out var expected) && expected == Type.GetTypeCode(type)) { return; } break; } System.Diagnostics.Debug.Fail($"value has wrong type '{type} for Expression kind '{kind}' "); }