26 lines
1.1 KiB
C#
26 lines
1.1 KiB
C#
using System.Net;
|
|
|
|
namespace SimpleHttpServer.Types;
|
|
|
|
public abstract class InternalEndpointCheckAttribute : Attribute {
|
|
/// <summary>
|
|
/// Executed when the endpoint is invoked. The endpoint invocation is skipped if any of the checks fail.
|
|
/// </summary>
|
|
/// <returns>True to allow invocation, false to prevent.</returns>
|
|
public abstract bool Check(HttpListenerRequest req);
|
|
internal abstract void SetInstance(object? instance);
|
|
}
|
|
|
|
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
|
|
public abstract class BaseEndpointCheckAttribute<T> : InternalEndpointCheckAttribute {
|
|
/// <summary>
|
|
/// A reference to the instance of the class that this attribute is attached to.
|
|
/// Will be null iff an class factory was passed in <see cref="HttpServer.RegisterEndpointsFromType{T}(Func{T}?)"/>.
|
|
/// </summary>
|
|
protected internal T? EndpointClassInstance { get; internal set; } = default;
|
|
public BaseEndpointCheckAttribute() { }
|
|
internal override void SetInstance(object? instance) {
|
|
if (instance != null)
|
|
EndpointClassInstance = (T?) instance;
|
|
}
|
|
} |