using System; namespace RestEase { /// /// Marks a parameter as able to substitute a placeholder in this method's path /// [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false, AllowMultiple = false)] public sealed class PathAttribute : Attribute { /// /// Gets or sets the optional name of the placeholder. Will use the parameter name if null /// public string? Name { get; set; } /// /// Gets the serialization method to use to serialize the value. Defaults to PathSerializationMethod.ToString /// public PathSerializationMethod SerializationMethod { get; set; } /// /// Gets or sets the format string used to format the value /// /// /// If is , this is passed to the serializer /// as . /// Otherwise, if this looks like a format string which can be passed to , /// (i.e. it contains at least one format placeholder), then this happens with the value passed as the first arg. /// Otherwise, if the value implements , this is passed to the value's /// method. Otherwise this is ignored. /// Example values: "X2", "{0:X2}", "test{0}". /// public string? Format { get; set; } /// /// Gets or sets a value indicating whether this path parameter should be URL-encoded. Defaults to true. /// public bool UrlEncode { get; set; } = true; /// /// Initialises a new instance of the class /// public PathAttribute() : this(PathSerializationMethod.Default) { } /// /// Initializes a new instance of the class, with the given serialization method /// /// Serialization method to use to serialize the value public PathAttribute(PathSerializationMethod serializationMethod) { // Don't set this.Name this.SerializationMethod = serializationMethod; } /// /// Initialises a new instance of the class, with the given name /// /// Placeholder in the path to replace public PathAttribute(string name) : this(name, PathSerializationMethod.Default) { } /// /// Initialises a new instance of the class, with the given name and serialization method /// /// Placeholder in the path to replace /// Serialization method to use to serialize the value public PathAttribute(string name, PathSerializationMethod serializationMethod) { this.Name = name; this.SerializationMethod = serializationMethod; } } }