Browse Source

Renamed generated stuff for sanity

Added API to create generated wrapper divorced from the config system
4.0.0-beta
Anairkoen Schno 4 years ago
parent
commit
7e4c460c00
6 changed files with 38 additions and 26 deletions
  1. +1
    -1
      IPA.Injector/Injector.cs
  2. +4
    -4
      IPA.Loader/Config/Stores/Attributes.cs
  3. +9
    -9
      IPA.Loader/Config/Stores/CustomObjectConverter.cs
  4. +22
    -10
      IPA.Loader/Config/Stores/GeneratedStoreImpl.cs
  5. +1
    -1
      IPA.Loader/Config/Stores/ValueConverter.cs
  6. +1
    -1
      IPA.Loader/IPA.Loader.csproj

+ 1
- 1
IPA.Injector/Injector.cs View File

@ -336,7 +336,7 @@ namespace IPA.Injector
PluginComponent.Create();
#if DEBUG
Config.Stores.GeneratedStore.DebugSaveAssembly("GeneratedAssembly.dll");
Config.Stores.GeneratedStoreImpl.DebugSaveAssembly("GeneratedAssembly.dll");
#endif
}
}

+ 4
- 4
IPA.Loader/Config/Stores/Attributes.cs View File

@ -15,14 +15,14 @@ namespace IPA.Config.Stores.Attributes
public sealed class NotifyPropertyChangesAttribute : Attribute { }
/// <summary>
/// Causes a field or property in an object being wrapped by <see cref="GeneratedExtension.Generated{T}(Config, bool)"/> to be
/// Causes a field or property in an object being wrapped by <see cref="GeneratedStore.Generated{T}(Config, bool)"/> to be
/// ignored during serialization and deserialization.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public sealed class IgnoreAttribute : Attribute { }
/// <summary>
/// Indicates that a field or property in an object being wrapped by <see cref="GeneratedExtension.Generated{T}(Config, bool)"/>
/// Indicates that a field or property in an object being wrapped by <see cref="GeneratedStore.Generated{T}(Config, bool)"/>
/// that would otherwise be nullable (i.e. a reference type or a <see cref="Nullable{T}"/> type) should never be null, and the
/// member will be ignored if the deserialized value is <see langword="null"/>.
/// </summary>
@ -30,7 +30,7 @@ namespace IPA.Config.Stores.Attributes
public sealed class NonNullableAttribute : Attribute { }
/// <summary>
/// Indicates that a given field or property in an object being wrapped by <see cref="GeneratedExtension.Generated{T}(Config, bool)"/>
/// Indicates that a given field or property in an object being wrapped by <see cref="GeneratedStore.Generated{T}(Config, bool)"/>
/// should be serialized and deserialized using the provided converter instead of the default mechanism.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
@ -74,7 +74,7 @@ namespace IPA.Config.Stores.Attributes
/// <summary>
/// Specifies a name for the serialized field or property in an object being wrapped by
/// <see cref="GeneratedExtension.Generated{T}(Config, bool)"/> that is different from the member name itself.
/// <see cref="GeneratedStore.Generated{T}(Config, bool)"/> that is different from the member name itself.
/// </summary>
/// <example>
/// <para>


+ 9
- 9
IPA.Loader/Config/Stores/CustomObjectConverter.cs View File

@ -4,10 +4,10 @@ using System;
namespace IPA.Config.Stores.Converters
{
/// <summary>
/// A <see cref="ValueConverter{T}"/> for objects normally serialized to config via <see cref="GeneratedExtension.Generated{T}(Config, bool)"/>.
/// A <see cref="ValueConverter{T}"/> for objects normally serialized to config via <see cref="GeneratedStore.Generated{T}(Config, bool)"/>.
/// </summary>
/// <typeparam name="T">the same type parameter that would be passed into <see cref="GeneratedExtension.Generated{T}(Config, bool)"/></typeparam>
/// <seealso cref="GeneratedExtension.Generated{T}(Config, bool)"/>
/// <typeparam name="T">the same type parameter that would be passed into <see cref="GeneratedStore.Generated{T}(Config, bool)"/></typeparam>
/// <seealso cref="GeneratedStore.Generated{T}(Config, bool)"/>
public class CustomObjectConverter<T> : ValueConverter<T> 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<U> : IImpl where U : class, GeneratedStore.IGeneratedStore<T>, T
private class Impl<U> : IImpl where U : class, GeneratedStoreImpl.IGeneratedStore<T>, 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))));
/// <summary>
/// Deserializes <paramref name="value"/> into a <typeparamref name="T"/> with the given <paramref name="parent"/>.


IPA.Loader/Config/Stores/GeneratedStore.cs → IPA.Loader/Config/Stores/GeneratedStoreImpl.cs View File

@ -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 <see cref="Config"/> to make it easy to use generated
/// config stores.
/// </summary>
public static class GeneratedExtension
public static class GeneratedStore
{
/// <summary>
/// The name of the assembly that internals must be visible to to allow internal protection.
/// </summary>
public const string AssemblyVisibilityTarget = GeneratedStore.GeneratedAssemblyName;
public const string AssemblyVisibilityTarget = GeneratedStoreImpl.GeneratedAssemblyName;
/// <summary>
/// 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
/// to allow the generated code to reference it.
/// <code>
/// [assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedExtension.AssemblyVisibilityTarget)]
/// [assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedStore.AssemblyVisibilityTarget)]
/// </code>
/// </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>
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);
if (loadSync)
cfg.LoadSync();
@ -106,9 +106,21 @@ namespace IPA.Config.Stores
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
{
@ -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<ParameterModifier>());
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
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);

+ 1
- 1
IPA.Loader/Config/Stores/ValueConverter.cs View File

@ -5,7 +5,7 @@ namespace IPA.Config.Stores
{
/// <summary>
/// The base interface for a value converter for use by objects generated by
/// <see cref="GeneratedExtension.Generated{T}(Config, bool)"/>.
/// <see cref="GeneratedStore.Generated{T}(Config, bool)"/>.
/// </summary>
/// <remarks>
/// <para>


+ 1
- 1
IPA.Loader/IPA.Loader.csproj View File

@ -102,7 +102,7 @@
<Compile Include="Config\Stores\Converters.cs" />
<Compile Include="Config\Stores\CustomObjectConverter.cs" />
<Compile Include="Config\Stores\CollectionConverter.cs" />
<Compile Include="Config\Stores\GeneratedStore.cs" />
<Compile Include="Config\Stores\GeneratedStoreImpl.cs" />
<Compile Include="Config\Stores\GeneratedStoreCollections.cs" />
<Compile Include="Config\Stores\ValueConverter.cs" />
<Compile Include="JsonConverters\AlmostVersionConverter.cs" />


Loading…
Cancel
Save