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