//
// ParameterChecker.cs
//
// Copyright (c) František Boháček. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using NosSmooth.PacketSerializersGenerator.Data;
using NosSmooth.PacketSerializersGenerator.Errors;
using NosSmooth.PacketSerializersGenerator.Extensions;
namespace NosSmooth.PacketSerializersGenerator;
///
/// Helpers for checking packet parameters.
///
public static class ParameterChecker
{
///
/// Checks that the given parameter has exactly one packet attribute.
///
/// The packet.
/// The parameter.
/// An error, if any.
public static IError? CheckHasOneAttribute(PacketInfo packetInfo, ParameterInfo parameter)
{
if (parameter.Attributes.Count > 1)
{
return new DiagnosticError
(
"SGAttr",
"Packet constructor parameter with multiple packet attributes",
"Found multiple packet attributes on parameter {0} in {1}. That is not supported for this type of packet attribute.",
parameter.Parameter.SyntaxTree,
parameter.Parameter.FullSpan,
new List