CSharpHttpServer/SimpleHttpServer/Types/ParameterAttribute.cs

19 lines
695 B
C#

namespace SimpleHttpServer.Types;
/// <summary>
/// Specifies the name of a http endpoint parameter. If this attribute is not specified, the variable name is used instead.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)]
public sealed class ParameterAttribute : Attribute {
public string Name { get; }
public bool IsOptional { get; }
public ParameterAttribute(string name, bool isOptional = false) {
if (string.IsNullOrWhiteSpace(name)) {
throw new ArgumentException($"'{nameof(name)}' cannot be null or whitespace.", nameof(name));
}
Name = name;
IsOptional = isOptional;
}
}