diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index 6967e81f..af82e74a 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -336,7 +336,7 @@ namespace IPA.Injector PluginComponent.Create(); #if DEBUG - Config.Stores.GeneratedStore.DebugSaveAssembly("GeneratedAssembly.dll"); + Config.Stores.GeneratedStoreImpl.DebugSaveAssembly("GeneratedAssembly.dll"); #endif } } diff --git a/IPA.Loader/Config/Stores/Attributes.cs b/IPA.Loader/Config/Stores/Attributes.cs index 87378e93..43fab747 100644 --- a/IPA.Loader/Config/Stores/Attributes.cs +++ b/IPA.Loader/Config/Stores/Attributes.cs @@ -15,14 +15,14 @@ namespace IPA.Config.Stores.Attributes public sealed class NotifyPropertyChangesAttribute : Attribute { } /// - /// Causes a field or property in an object being wrapped by to be + /// Causes a field or property in an object being wrapped by to be /// ignored during serialization and deserialization. /// [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public sealed class IgnoreAttribute : Attribute { } /// - /// Indicates that a field or property in an object being wrapped by + /// Indicates that a field or property in an object being wrapped by /// that would otherwise be nullable (i.e. a reference type or a type) should never be null, and the /// member will be ignored if the deserialized value is . /// @@ -30,7 +30,7 @@ namespace IPA.Config.Stores.Attributes public sealed class NonNullableAttribute : Attribute { } /// - /// Indicates that a given field or property in an object being wrapped by + /// Indicates that a given field or property in an object being wrapped by /// should be serialized and deserialized using the provided converter instead of the default mechanism. /// [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] @@ -74,7 +74,7 @@ namespace IPA.Config.Stores.Attributes /// /// Specifies a name for the serialized field or property in an object being wrapped by - /// that is different from the member name itself. + /// that is different from the member name itself. /// /// /// diff --git a/IPA.Loader/Config/Stores/CustomObjectConverter.cs b/IPA.Loader/Config/Stores/CustomObjectConverter.cs index 1df4f7b6..c397fe37 100644 --- a/IPA.Loader/Config/Stores/CustomObjectConverter.cs +++ b/IPA.Loader/Config/Stores/CustomObjectConverter.cs @@ -4,10 +4,10 @@ using System; namespace IPA.Config.Stores.Converters { /// - /// A for objects normally serialized to config via . + /// A for objects normally serialized to config via . /// - /// the same type parameter that would be passed into - /// + /// the same type parameter that would be passed into + /// public class CustomObjectConverter : ValueConverter where T : class { private interface IImpl @@ -15,22 +15,22 @@ namespace IPA.Config.Stores.Converters T FromValue(Value value, object parent); Value ToValue(T obj, object parent); } - private class Impl : IImpl where U : class, GeneratedStore.IGeneratedStore, T + private class Impl : IImpl where U : class, GeneratedStoreImpl.IGeneratedStore, T { - private static readonly GeneratedStore.GeneratedStoreCreator creator = GeneratedStore.GetCreator(typeof(T)); - private static U Create(GeneratedStore.IGeneratedStore parent) + private static readonly GeneratedStoreImpl.GeneratedStoreCreator creator = GeneratedStoreImpl.GetCreator(typeof(T)); + private static U Create(GeneratedStoreImpl.IGeneratedStore parent) => creator(parent) as U; public T FromValue(Value value, object parent) { // lots of casting here, but it works i promise (probably) (parent can be a non-IGeneratedStore, however it won't necessarily behave then) - var obj = Create(parent as GeneratedStore.IGeneratedStore); + var obj = Create(parent as GeneratedStoreImpl.IGeneratedStore); obj.Deserialize(value); return obj; } public Value ToValue(T obj, object parent) { - if (obj is GeneratedStore.IGeneratedStore store) + if (obj is GeneratedStoreImpl.IGeneratedStore store) return store.Serialize(); else { @@ -42,7 +42,7 @@ namespace IPA.Config.Stores.Converters } private static readonly IImpl impl = (IImpl)Activator.CreateInstance( - typeof(Impl<>).MakeGenericType(GeneratedStore.GetGeneratedType(typeof(T)))); + typeof(Impl<>).MakeGenericType(GeneratedStoreImpl.GetGeneratedType(typeof(T)))); /// /// Deserializes into a with the given . diff --git a/IPA.Loader/Config/Stores/GeneratedStore.cs b/IPA.Loader/Config/Stores/GeneratedStoreImpl.cs similarity index 98% rename from IPA.Loader/Config/Stores/GeneratedStore.cs rename to IPA.Loader/Config/Stores/GeneratedStoreImpl.cs index 1b87df5e..c0bcbed6 100644 --- a/IPA.Loader/Config/Stores/GeneratedStore.cs +++ b/IPA.Loader/Config/Stores/GeneratedStoreImpl.cs @@ -21,7 +21,7 @@ using Net3_Proxy; using Array = Net3_Proxy.Array; #endif -[assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedExtension.AssemblyVisibilityTarget)] +[assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedStore.AssemblyVisibilityTarget)] namespace IPA.Config.Stores { @@ -29,12 +29,12 @@ namespace IPA.Config.Stores /// A class providing an extension for to make it easy to use generated /// config stores. /// - public static class GeneratedExtension + public static class GeneratedStore { /// /// The name of the assembly that internals must be visible to to allow internal protection. /// - public const string AssemblyVisibilityTarget = GeneratedStore.GeneratedAssemblyName; + public const string AssemblyVisibilityTarget = GeneratedStoreImpl.GeneratedAssemblyName; /// /// Creates a generated of type , 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 /// to allow the generated code to reference it. /// - /// [assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedExtension.AssemblyVisibilityTarget)] + /// [assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedStore.AssemblyVisibilityTarget)] /// /// /// @@ -97,7 +97,7 @@ namespace IPA.Config.Stores /// a generated instance of as a special public static T Generated(this Config cfg, bool loadSync = true) where T : class { - var ret = GeneratedStore.Create(); + var ret = GeneratedStoreImpl.Create(); cfg.SetStore(ret as IConfigStore); if (loadSync) cfg.LoadSync(); @@ -106,9 +106,21 @@ namespace IPA.Config.Stores return ret; } + + /// + /// Creates a generated store outside of the context of the config system. + /// + /// + /// See for more information about how it behaves. + /// + /// the type to wrap + /// a generated instance of implementing functionality described by + /// + public static T Create() where T : class + => GeneratedStoreImpl.Create(); } - internal static class GeneratedStore + internal static class GeneratedStoreImpl { internal interface IGeneratedStore { @@ -279,7 +291,7 @@ namespace IPA.Config.Stores public static IConfigStore Create(Type type) => Create(type, null); 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()); internal static T Create(IGeneratedStore parent) where T : class => (T)Create(typeof(T), parent); @@ -1228,17 +1240,17 @@ namespace IPA.Config.Stores } #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) { 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) { 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) { Logger.config.Warn(exception); diff --git a/IPA.Loader/Config/Stores/ValueConverter.cs b/IPA.Loader/Config/Stores/ValueConverter.cs index bd3dd555..8be1f300 100644 --- a/IPA.Loader/Config/Stores/ValueConverter.cs +++ b/IPA.Loader/Config/Stores/ValueConverter.cs @@ -5,7 +5,7 @@ namespace IPA.Config.Stores { /// /// The base interface for a value converter for use by objects generated by - /// . + /// . /// /// /// diff --git a/IPA.Loader/IPA.Loader.csproj b/IPA.Loader/IPA.Loader.csproj index 3f1dbfe8..eeae4da3 100644 --- a/IPA.Loader/IPA.Loader.csproj +++ b/IPA.Loader/IPA.Loader.csproj @@ -102,7 +102,7 @@ - +