From 0918190f9cbd02943631492b94cb7c2cb79418b9 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Mon, 31 Aug 2020 02:18:15 -0500 Subject: [PATCH] Updated Build Status badge on documentation --- IPA.Loader/Config/Stores/Converters.cs | 14 +- .../GeneratedStoreImpl/GeneratedStoreImpl.cs | 260 +++++++++--------- .../GeneratedStoreImpl/ObjectStructure.cs | 2 +- docs/index.md | 2 +- 4 files changed, 139 insertions(+), 139 deletions(-) diff --git a/IPA.Loader/Config/Stores/Converters.cs b/IPA.Loader/Config/Stores/Converters.cs index ba8b6c10..34796221 100644 --- a/IPA.Loader/Config/Stores/Converters.cs +++ b/IPA.Loader/Config/Stores/Converters.cs @@ -13,7 +13,7 @@ namespace IPA.Config.Stores.Converters /// /// Provides utility functions for custom converters. /// - public static class Converter + public static class Converter { /// /// Gets the integral value of a , coercing a if necessary, @@ -206,8 +206,8 @@ namespace IPA.Config.Stores.Converters /// the underlying type of the /// the type to use as an underlying converter /// - public sealed class NullableConverter : NullableConverter - where T : struct + public sealed class NullableConverter : NullableConverter + where T : struct where TConverter : ValueConverter, new() { /// @@ -291,7 +291,7 @@ namespace IPA.Config.Stores.Converters /// the deserialized enum value /// if is not a numeric node public override T FromValue(Value value, object parent) - => (T)Enum.ToObject(typeof(T), Converter.IntValue(value) + => (T)Enum.ToObject(typeof(T), Converter.IntValue(value) ?? throw new ArgumentException("Value not a numeric node", nameof(value))); /// @@ -494,7 +494,7 @@ namespace IPA.Config.Stores.Converters internal class CharConverter : ValueConverter { public override char FromValue(Value value, object parent) - => (value as Text)?.Value[0] + => (value as Text)?.Value[0] ?? throw new ArgumentException("Value not a text node", nameof(value)); // can throw nullptr public override Value ToValue(char obj, object parent) @@ -504,7 +504,7 @@ namespace IPA.Config.Stores.Converters internal class LongConverter : ValueConverter { public override long FromValue(Value value, object parent) - => Converter.IntValue(value) + => Converter.IntValue(value) ?? throw new ArgumentException("Value not a numeric value", nameof(value)); public override Value ToValue(long obj, object parent) @@ -514,7 +514,7 @@ namespace IPA.Config.Stores.Converters internal class ULongConverter : ValueConverter { public override ulong FromValue(Value value, object parent) - => (ulong)(Converter.FloatValue(value) + => (ulong)(Converter.FloatValue(value) ?? throw new ArgumentException("Value not a numeric value", nameof(value))); public override Value ToValue(ulong obj, object parent) diff --git a/IPA.Loader/Config/Stores/GeneratedStoreImpl/GeneratedStoreImpl.cs b/IPA.Loader/Config/Stores/GeneratedStoreImpl/GeneratedStoreImpl.cs index e75aa819..c069905f 100644 --- a/IPA.Loader/Config/Stores/GeneratedStoreImpl/GeneratedStoreImpl.cs +++ b/IPA.Loader/Config/Stores/GeneratedStoreImpl/GeneratedStoreImpl.cs @@ -1,132 +1,132 @@ -using IPA.Config.Data; -using IPA.Config.Stores.Attributes; -using IPA.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Reflection.Emit; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Linq.Expressions; -using System.Runtime.CompilerServices; -using System.IO; -using Boolean = IPA.Config.Data.Boolean; -using System.Collections; -using IPA.Utilities; -using System.ComponentModel; -using System.Collections.Concurrent; +using IPA.Config.Data; +using IPA.Config.Stores.Attributes; +using IPA.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Reflection.Emit; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Linq.Expressions; +using System.Runtime.CompilerServices; +using System.IO; +using Boolean = IPA.Config.Data.Boolean; +using System.Collections; +using IPA.Utilities; +using System.ComponentModel; +using System.Collections.Concurrent; using IPA.Utilities.Async; -#if NET3 -using Net3_Proxy; -using Array = Net3_Proxy.Array; -#endif - -[assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedStore.AssemblyVisibilityTarget)] - -namespace IPA.Config.Stores -{ - internal static partial class GeneratedStoreImpl - { - public static T Create() where T : class => (T)Create(typeof(T)); - - public static IConfigStore Create(Type type) => Create(type, null); - - private static readonly MethodInfo CreateGParent = - 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); - - private static IConfigStore Create(Type type, IGeneratedStore parent) - => GetCreator(type)(parent); - - private static readonly SingleCreationValueCache generatedCreators - = new SingleCreationValueCache(); - +#if NET3 +using Net3_Proxy; +using Array = Net3_Proxy.Array; +#endif + +[assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedStore.AssemblyVisibilityTarget)] + +namespace IPA.Config.Stores +{ + internal static partial class GeneratedStoreImpl + { + public static T Create() where T : class => (T)Create(typeof(T)); + + public static IConfigStore Create(Type type) => Create(type, null); + + private static readonly MethodInfo CreateGParent = + 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); + + private static IConfigStore Create(Type type, IGeneratedStore parent) + => GetCreator(type)(parent); + + private static readonly SingleCreationValueCache generatedCreators + = new SingleCreationValueCache(); + private static (GeneratedStoreCreator ctor, Type type) GetCreatorAndGeneratedType(Type t) - => generatedCreators.GetOrAdd(t, MakeCreator); - - internal static GeneratedStoreCreator GetCreator(Type t) - => GetCreatorAndGeneratedType(t).ctor; - - internal static Type GetGeneratedType(Type t) - => GetCreatorAndGeneratedType(t).type; - - internal const string GeneratedAssemblyName = "IPA.Config.Generated"; - - private static AssemblyBuilder assembly = null; - private static AssemblyBuilder Assembly - { - get - { - if (assembly == null) - { - var name = new AssemblyName(GeneratedAssemblyName); - assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave); - } - - return assembly; - } - } - - internal static void DebugSaveAssembly(string file) - { - Assembly.Save(file); - } - - private static ModuleBuilder module = null; - private static ModuleBuilder Module - { - get - { - if (module == null) - module = Assembly.DefineDynamicModule(Assembly.GetName().Name, Assembly.GetName().Name + ".dll"); - - return module; - } - } - - // TODO: does this need to be a SingleCreationValueCache or similar? - private static readonly Dictionary> TypeRequiredConverters = new Dictionary>(); - private static void CreateAndInitializeConvertersFor(Type type, IEnumerable structure) - { - if (!TypeRequiredConverters.TryGetValue(type, out var converters)) - { - var converterFieldType = Module.DefineType($"{type.FullName}", - TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract | TypeAttributes.AnsiClass); // a static class - - var uniqueConverterTypes = structure.Where(m => m.HasConverter).Select(m => m.Converter).Distinct().ToArray(); - converters = new Dictionary(uniqueConverterTypes.Length); - - foreach (var convType in uniqueConverterTypes) - { - var field = converterFieldType.DefineField($"_{convType}", convType, - FieldAttributes.FamORAssem | FieldAttributes.InitOnly | FieldAttributes.Static); - converters.Add(convType, field); - } - - var cctor = converterFieldType.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, Type.EmptyTypes); - { - var il = cctor.GetILGenerator(); - - foreach (var kvp in converters) - { - var typeCtor = kvp.Key.GetConstructor(Type.EmptyTypes); - il.Emit(OpCodes.Newobj, typeCtor); - il.Emit(OpCodes.Stsfld, kvp.Value); - } - - il.Emit(OpCodes.Ret); - } - - TypeRequiredConverters.Add(type, converters); - - converterFieldType.CreateType(); - } - - foreach (var member in structure.Where(m => m.HasConverter)) - member.ConverterField = converters[member.Converter]; - } - } -} + => generatedCreators.GetOrAdd(t, MakeCreator); + + internal static GeneratedStoreCreator GetCreator(Type t) + => GetCreatorAndGeneratedType(t).ctor; + + internal static Type GetGeneratedType(Type t) + => GetCreatorAndGeneratedType(t).type; + + internal const string GeneratedAssemblyName = "IPA.Config.Generated"; + + private static AssemblyBuilder assembly = null; + private static AssemblyBuilder Assembly + { + get + { + if (assembly == null) + { + var name = new AssemblyName(GeneratedAssemblyName); + assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave); + } + + return assembly; + } + } + + internal static void DebugSaveAssembly(string file) + { + Assembly.Save(file); + } + + private static ModuleBuilder module = null; + private static ModuleBuilder Module + { + get + { + if (module == null) + module = Assembly.DefineDynamicModule(Assembly.GetName().Name, Assembly.GetName().Name + ".dll"); + + return module; + } + } + + // TODO: does this need to be a SingleCreationValueCache or similar? + private static readonly Dictionary> TypeRequiredConverters = new Dictionary>(); + private static void CreateAndInitializeConvertersFor(Type type, IEnumerable structure) + { + if (!TypeRequiredConverters.TryGetValue(type, out var converters)) + { + var converterFieldType = Module.DefineType($"{type.FullName}", + TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract | TypeAttributes.AnsiClass); // a static class + + var uniqueConverterTypes = structure.Where(m => m.HasConverter).Select(m => m.Converter).Distinct().ToArray(); + converters = new Dictionary(uniqueConverterTypes.Length); + + foreach (var convType in uniqueConverterTypes) + { + var field = converterFieldType.DefineField($"_{convType}", convType, + FieldAttributes.FamORAssem | FieldAttributes.InitOnly | FieldAttributes.Static); + converters.Add(convType, field); + } + + var cctor = converterFieldType.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, Type.EmptyTypes); + { + var il = cctor.GetILGenerator(); + + foreach (var kvp in converters) + { + var typeCtor = kvp.Key.GetConstructor(Type.EmptyTypes); + il.Emit(OpCodes.Newobj, typeCtor); + il.Emit(OpCodes.Stsfld, kvp.Value); + } + + il.Emit(OpCodes.Ret); + } + + TypeRequiredConverters.Add(type, converters); + + converterFieldType.CreateType(); + } + + foreach (var member in structure.Where(m => m.HasConverter)) + member.ConverterField = converters[member.Converter]; + } + } +} diff --git a/IPA.Loader/Config/Stores/GeneratedStoreImpl/ObjectStructure.cs b/IPA.Loader/Config/Stores/GeneratedStoreImpl/ObjectStructure.cs index aa443657..baefefa0 100644 --- a/IPA.Loader/Config/Stores/GeneratedStoreImpl/ObjectStructure.cs +++ b/IPA.Loader/Config/Stores/GeneratedStoreImpl/ObjectStructure.cs @@ -147,7 +147,7 @@ namespace IPA.Config.Stores } if (prop.GetGetMethod(true)?.IsPrivate ?? true) { // we enter this block if the getter is inacessible or doesn't exist - continue; // ignore props without getter + continue; // ignore props without getter } var smi = new SerializedMemberInfo diff --git a/docs/index.md b/docs/index.md index c4364e3a..dd45e0d1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5,7 +5,7 @@ uid: home # ![BSIPA](images/banner_dark.svg) -[![Build status](https://ci.appveyor.com/api/projects/status/1ruhnnfeudrrd097?svg=true)](https://ci.appveyor.com/project/nike4613/beatsaber-ipa-reloaded-9smsb) +[![Build](https://github.com/bsmg/BeatSaber-IPA-Reloaded/workflows/Build/badge.svg)](https://ci.appveyor.com/project/nike4613/beatsaber-ipa-reloaded-9smsb) BSIPA - The Unity mod injector for the new age (pending confirmation).