diff --git a/src/AutoInjectSystem.cs b/src/AutoInjectSystem.cs index e10a5e9..fa9c4b2 100644 --- a/src/AutoInjectSystem.cs +++ b/src/AutoInjectSystem.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using static DCFApixels.DragonECS.EcsThrowHalper; namespace DCFApixels.DragonECS { @@ -51,8 +52,7 @@ namespace DCFApixels.DragonECS if (o.GetCustomAttribute() == null) return false; #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (o.CanWrite == false) - throw new EcsAutoInjectionException($"{o.Name} property is cant write"); + if (o.CanWrite == false) Throw.PropertyIsCantWrite(o); #endif return true; }) @@ -63,10 +63,8 @@ namespace DCFApixels.DragonECS if (o.GetCustomAttribute() == null) return false; #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (o.IsGenericMethod) - throw new EcsAutoInjectionException($"{o.Name} method is Generic"); - if (o.GetParameters().Length != 1) - throw new EcsAutoInjectionException($"{o.Name} method Arguments != 1"); + if (o.IsGenericMethod) Throw.MethodIsGeneric(o); + if (o.GetParameters().Length != 1) Throw.MethodArgumentsGreater1(o); #endif return true; }) diff --git a/src/Utils/Exceptions.cs b/src/Utils/Exceptions.cs index 84f5ea0..9fb2a7f 100644 --- a/src/Utils/Exceptions.cs +++ b/src/Utils/Exceptions.cs @@ -1,8 +1,30 @@ using System; +using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.Serialization; namespace DCFApixels.DragonECS { + public static class EcsThrowHalper_AutoInjections + { + [MethodImpl(MethodImplOptions.NoInlining)] + internal static void PropertyIsCantWrite(this EcsThrowHalper _, MemberInfo obj) + { + throw new EcsAutoInjectionException($"{obj.Name} property is cant write"); + } + [MethodImpl(MethodImplOptions.NoInlining)] + internal static void MethodIsGeneric(this EcsThrowHalper _, MemberInfo obj) + { + throw new EcsAutoInjectionException($"{obj.Name} method is Generic"); + } + [MethodImpl(MethodImplOptions.NoInlining)] + internal static void MethodArgumentsGreater1(this EcsThrowHalper _, MemberInfo obj) + { + //method X has arguments greater than 1. + throw new EcsAutoInjectionException($"{obj.Name} method Arguments != 1"); + } + } + [Serializable] public class EcsAutoInjectionException : Exception {