baseline: OpenMU upstream b5a0961 (fresh source)

This commit is contained in:
Acentech Dev
2026-07-14 19:00:35 +03:00
parent 450402e47d
commit 36fc125d5c
11968 changed files with 748705 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
// <copyright file="TypeExtensions.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
namespace MUnique.OpenMU.PlugIns;
/// <summary>
/// Extension methods for <see cref="Type"/>.
/// </summary>
public static class TypeExtensions
{
/// <summary>
/// Gets the implemented interface of <see cref="ISupportCustomConfiguration{T}"/>.
/// </summary>
/// <param name="plugInType">Type of the plug in.</param>
/// <returns>The implemented interface of <see cref="ISupportCustomConfiguration{T}"/>.</returns>
public static Type? GetCustomConfigurationSupportInterfaceType(this Type plugInType)
{
return plugInType.GetInterfaces()
.Where(i => i.IsGenericType)
.FirstOrDefault(i => i.GetGenericTypeDefinition() == typeof(ISupportCustomConfiguration<>));
}
/// <summary>
/// Gets the generic type parameter of <see cref="ISupportCustomConfiguration{T}"/>.
/// </summary>
/// <param name="plugInType">Type of the plug in.</param>
/// <returns>The generic type parameter of <see cref="ISupportCustomConfiguration{T}"/>.</returns>
public static Type? GetCustomConfigurationType(this Type plugInType)
{
if (plugInType.GetCustomConfigurationSupportInterfaceType() is { } configSupportInterface)
{
return configSupportInterface.GenericTypeArguments[0];
}
return null;
}
/// <summary>
/// Determines whether this type is a <see cref="Nullable{T}"/>.
/// </summary>
/// <param name="type">The type.</param>
/// <returns>
/// <c>true</c> if the specified type is a nullable; otherwise, <c>false</c>.
/// </returns>
public static bool IsNullable(this Type type) => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
/// <summary>
/// Gets the generic type argument of the nullable.
/// </summary>
/// <param name="type">The nullable type.</param>
/// <returns>The generic type argument of the nullable.</returns>
public static Type GetTypeOfNullable(this Type type) => type.IsNullable() ? type.GetGenericArguments().First() : type;
}