summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/InternalControllerFeatureProvider.cs
blob: 98738a827c1b488c9fef0c5a4714b3a44bc3274e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#nullable disable

using System;
using System.Reflection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;

namespace StardewModdingAPI.Web.Framework
{
    /// <summary>Discovers controllers with support for non-public controllers.</summary>
    internal class InternalControllerFeatureProvider : ControllerFeatureProvider
    {
        /*********
        ** Public methods
        *********/
        /// <summary>Determines if a given type is a controller.</summary>
        /// <param name="type">The <see cref="T:System.Reflection.TypeInfo" /> candidate.</param>
        /// <returns><code>true</code> if the type is a controller; otherwise <code>false</code>.</returns>
        protected override bool IsController(TypeInfo type)
        {
            return
                type.IsClass
                && !type.IsAbstract
                && (/*type.IsPublic &&*/ !type.ContainsGenericParameters)
                && (!type.IsDefined(typeof(NonControllerAttribute))
                && (type.Name.EndsWith("Controller", StringComparison.OrdinalIgnoreCase) || type.IsDefined(typeof(ControllerAttribute))));
        }
    }
}