@ -21,7 +21,7 @@ using Net3_Proxy;
using Array = Net3_Proxy . Array ;
using Array = Net3_Proxy . Array ;
#endif
#endif
[assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedExtension .AssemblyVisibilityTarget)]
[assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedStore .AssemblyVisibilityTarget)]
namespace IPA.Config.Stores
namespace IPA.Config.Stores
{
{
@ -29,12 +29,12 @@ namespace IPA.Config.Stores
/// A class providing an extension for <see cref="Config"/> to make it easy to use generated
/// A class providing an extension for <see cref="Config"/> to make it easy to use generated
/// config stores.
/// config stores.
/// </summary>
/// </summary>
public static class GeneratedExtension
public static class GeneratedStore
{
{
/// <summary>
/// <summary>
/// The name of the assembly that internals must be visible to to allow internal protection.
/// The name of the assembly that internals must be visible to to allow internal protection.
/// </summary>
/// </summary>
public const string AssemblyVisibilityTarget = GeneratedStore . GeneratedAssemblyName ;
public const string AssemblyVisibilityTarget = GeneratedStoreImpl . GeneratedAssemblyName ;
/// <summary>
/// <summary>
/// Creates a generated <see cref="IConfigStore"/> of type <typeparamref name="T"/>, registers it to
/// Creates a generated <see cref="IConfigStore"/> of type <typeparamref name="T"/>, registers it to
@ -47,7 +47,7 @@ namespace IPA.Config.Stores
/// It can also be internal, but in that case, then your assembly must have the following attribute
/// It can also be internal, but in that case, then your assembly must have the following attribute
/// to allow the generated code to reference it.
/// to allow the generated code to reference it.
/// <code>
/// <code>
/// [assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedExtension .AssemblyVisibilityTarget)]
/// [assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedStore .AssemblyVisibilityTarget)]
/// </code>
/// </code>
/// </para>
/// </para>
/// <para>
/// <para>
@ -97,7 +97,7 @@ namespace IPA.Config.Stores
/// <returns>a generated instance of <typeparamref name="T"/> as a special <see cref="IConfigStore"/></returns>
/// <returns>a generated instance of <typeparamref name="T"/> as a special <see cref="IConfigStore"/></returns>
public static T Generated < T > ( this Config cfg , bool loadSync = true ) where T : class
public static T Generated < T > ( this Config cfg , bool loadSync = true ) where T : class
{
{
var ret = GeneratedStore . Create < T > ( ) ;
var ret = GeneratedStoreImpl . Create < T > ( ) ;
cfg . SetStore ( ret as IConfigStore ) ;
cfg . SetStore ( ret as IConfigStore ) ;
if ( loadSync )
if ( loadSync )
cfg . LoadSync ( ) ;
cfg . LoadSync ( ) ;
@ -106,9 +106,21 @@ namespace IPA.Config.Stores
return ret ;
return ret ;
}
}
/// <summary>
/// Creates a generated store outside of the context of the config system.
/// </summary>
/// <remarks>
/// See <see cref="Generated{T}(Config, bool)"/> for more information about how it behaves.
/// </remarks>
/// <typeparam name="T">the type to wrap</typeparam>
/// <returns>a generated instance of <typeparamref name="T"/> implementing functionality described by <see cref="Generated{T}(Config, bool)"/></returns>
/// <seealso cref="Generated{T}(Config, bool)"/>
public static T Create < T > ( ) where T : class
= > GeneratedStoreImpl . Create < T > ( ) ;
}
}
internal static class GeneratedStore
internal static class GeneratedStoreImpl
{
{
internal interface IGeneratedStore
internal interface IGeneratedStore
{
{
@ -279,7 +291,7 @@ namespace IPA.Config.Stores
public static IConfigStore Create ( Type type ) = > Create ( type , null ) ;
public static IConfigStore Create ( Type type ) = > Create ( type , null ) ;
private static readonly MethodInfo CreateGParent =
private static readonly MethodInfo CreateGParent =
typeof ( GeneratedStore ) . GetMethod ( nameof ( Create ) , BindingFlags . NonPublic | BindingFlags . Static , null ,
typeof ( GeneratedStoreImpl ) . GetMethod ( nameof ( Create ) , BindingFlags . NonPublic | BindingFlags . Static , null ,
CallingConventions . Any , new [ ] { typeof ( IGeneratedStore ) } , Array . Empty < ParameterModifier > ( ) ) ;
CallingConventions . Any , new [ ] { typeof ( IGeneratedStore ) } , Array . Empty < ParameterModifier > ( ) ) ;
internal static T Create < T > ( IGeneratedStore parent ) where T : class = > ( T ) Create ( typeof ( T ) , parent ) ;
internal static T Create < T > ( IGeneratedStore parent ) where T : class = > ( T ) Create ( typeof ( T ) , parent ) ;
@ -1228,17 +1240,17 @@ namespace IPA.Config.Stores
}
}
#region Logs
#region Logs
private static readonly MethodInfo LogErrorMethod = typeof ( GeneratedStore ) . GetMethod ( nameof ( LogError ) , BindingFlags . NonPublic | BindingFlags . Static ) ;
private static readonly MethodInfo LogErrorMethod = typeof ( GeneratedStoreImpl ) . GetMethod ( nameof ( LogError ) , BindingFlags . NonPublic | BindingFlags . Static ) ;
internal static void LogError ( Type expected , Type found , string message )
internal static void LogError ( Type expected , Type found , string message )
{
{
Logger . config . Notice ( $"{message}{(expected == null ? "" : $" ( expected { expected } , found { found ? . ToString ( ) ? ? "null" } ) ")}" ) ;
Logger . config . Notice ( $"{message}{(expected == null ? "" : $" ( expected { expected } , found { found ? . ToString ( ) ? ? "null" } ) ")}" ) ;
}
}
private static readonly MethodInfo LogWarningMethod = typeof ( GeneratedStore ) . GetMethod ( nameof ( LogWarning ) , BindingFlags . NonPublic | BindingFlags . Static ) ;
private static readonly MethodInfo LogWarningMethod = typeof ( GeneratedStoreImpl ) . GetMethod ( nameof ( LogWarning ) , BindingFlags . NonPublic | BindingFlags . Static ) ;
internal static void LogWarning ( string message )
internal static void LogWarning ( string message )
{
{
Logger . config . Warn ( message ) ;
Logger . config . Warn ( message ) ;
}
}
private static readonly MethodInfo LogWarningExceptionMethod = typeof ( GeneratedStore ) . GetMethod ( nameof ( LogWarningException ) , BindingFlags . NonPublic | BindingFlags . Static ) ;
private static readonly MethodInfo LogWarningExceptionMethod = typeof ( GeneratedStoreImpl ) . GetMethod ( nameof ( LogWarningException ) , BindingFlags . NonPublic | BindingFlags . Static ) ;
internal static void LogWarningException ( Exception exception )
internal static void LogWarningException ( Exception exception )
{
{
Logger . config . Warn ( exception ) ;
Logger . config . Warn ( exception ) ;