using System; using System.Collections.Generic; namespace RestEase.Implementation { /// /// Class containing information about a desired path parameter /// public abstract class PathParameterInfo { /// /// Gets a value indicating whether this path parameter should be URL-encoded /// public bool UrlEncode { get; protected set; } /// /// Gets the method to use to serialize the path parameter. /// public PathSerializationMethod SerializationMethod { get; protected set; } /// /// Serialize the value into a name -> value pair using the given serializer /// /// Serializer to use /// RequestInfo representing the request /// given to the , if any /// Serialized value public abstract KeyValuePair SerializeValue(RequestPathParamSerializer serializer, IRequestInfo requestInfo, IFormatProvider? formatProvider); /// /// Serialize the value into a name -> value pair using its ToString method /// /// given to the , if any /// Serialized value public abstract KeyValuePair SerializeToString(IFormatProvider? formatProvider); } /// /// Class containing information about a desired path parameter /// /// Type of the value public class PathParameterInfo : PathParameterInfo { private readonly string name; private readonly T value; private readonly string? format; /// /// Initialises a new instance of the Structure /// /// Name of the name/value pair /// Value of the name/value pair /// Format string to use /// Indicates whether this parameter should be url-encoded /// Method to use to serialize the path value. public PathParameterInfo(string name, T value, string? format, bool urlEncode, PathSerializationMethod serializationMethod) { this.name = name; this.value = value; this.format = format; this.UrlEncode = urlEncode; this.SerializationMethod = serializationMethod; } /// /// Serialize the value into a name -> value pair using the given serializer /// /// Serializer to use /// RequestInfo representing the request /// given to the , if any /// Serialized value public override KeyValuePair SerializeValue(RequestPathParamSerializer serializer, IRequestInfo requestInfo, IFormatProvider? formatProvider) { if (serializer == null) throw new ArgumentNullException(nameof(serializer)); if (requestInfo == null) throw new ArgumentNullException(nameof(requestInfo)); string? serializedValue = serializer.SerializePathParam(this.value, new RequestPathParamSerializerInfo(requestInfo, this.format, formatProvider)); return new KeyValuePair(this.name, serializedValue); } /// /// Serialize the value into a name -> value pair using its ToString method /// /// given to the , if any /// Serialized value public override KeyValuePair SerializeToString(IFormatProvider? formatProvider) { return new KeyValuePair(this.name, ToStringHelper.ToString(this.value, this.format, formatProvider)); } } }