From 090dbc9c5af608ecf77ecf0387f5986163575368 Mon Sep 17 00:00:00 2001 From: labbbirder <502100554@qq.com> Date: Mon, 1 Apr 2024 18:45:47 +0800 Subject: [PATCH] chore: update dependency dra --- Runtime/ClassicalUsages/DecoratorAttribute.cs | 4 +-- Runtime/ClassicalUsages/SimpleDIAttribute.cs | 28 +++++++++---------- Runtime/FixHelper.cs | 2 +- package.json | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Runtime/ClassicalUsages/DecoratorAttribute.cs b/Runtime/ClassicalUsages/DecoratorAttribute.cs index c0a1ac0..8a78b06 100644 --- a/Runtime/ClassicalUsages/DecoratorAttribute.cs +++ b/Runtime/ClassicalUsages/DecoratorAttribute.cs @@ -21,11 +21,11 @@ public abstract partial class DecoratorAttribute : InjectionAttribute /// /// public bool IsAsyncMethod - => m_IsAsyncMethod ??= targetMember.GetCustomAttribute() != null; + => m_IsAsyncMethod ??= targetInfo.GetCustomAttribute() != null; public override IEnumerable ProvideInjections() { - var InjectedMethod = this.targetMember as MethodInfo; + var InjectedMethod = this.targetInfo as MethodInfo; var OriginSavingField = ThisType.GetField(nameof(originFunc), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); var OriginSavingTarget = this; diff --git a/Runtime/ClassicalUsages/SimpleDIAttribute.cs b/Runtime/ClassicalUsages/SimpleDIAttribute.cs index c0a8e5d..b2d92a1 100644 --- a/Runtime/ClassicalUsages/SimpleDIAttribute.cs +++ b/Runtime/ClassicalUsages/SimpleDIAttribute.cs @@ -95,11 +95,11 @@ public override IEnumerable ProvideInjections() s_MetaMethodInfo ??= typeof(SimpleDIAttribute).GetMethod(nameof(MetaGet), Static | NonPublic); s_StaticMetaMethodInfo ??= typeof(SimpleDIAttribute).GetMethod(nameof(StaticMetaGet), Static | NonPublic); s_miMetaConstructor ??= typeof(SimpleDIAttribute).GetMethod(nameof(MetaConstructor), Static | NonPublic); - if (targetMember is not PropertyInfo and not FieldInfo) - throw new Exception($"cannot inject {targetMember} on type {targetType}, only fields and properties allowed"); - var memberType = GetMemberType(targetMember); - var isStatic = IsStatic(targetMember); - var canWrite = CanWrite(targetMember); + if (targetInfo is not PropertyInfo and not FieldInfo) + throw new Exception($"cannot inject {targetInfo} on type {targetInfo.DeclaringType}, only fields and properties allowed"); + var memberType = GetMemberType(targetInfo); + var isStatic = IsStatic(targetInfo); + var canWrite = CanWrite(targetInfo); // var declaringType = targetMember.DeclaringType; if (isStatic) { @@ -108,14 +108,14 @@ public override IEnumerable ProvideInjections() // set on fix instantly yield return InjectionInfo.Create(() => { - SetMemberValue(targetMember, null, GetContainerInst(memberType, targetType)); + SetMemberValue(targetInfo, null, GetContainerInst(memberType, targetInfo.DeclaringType)); }); } else { // inject get method - var propertyInfo = targetMember as PropertyInfo; - var fixingMethod = s_StaticMetaMethodInfo.MakeGenericMethod(propertyInfo.PropertyType, targetType); + var propertyInfo = targetInfo as PropertyInfo; + var fixingMethod = s_StaticMetaMethodInfo.MakeGenericMethod(propertyInfo.PropertyType, targetInfo.DeclaringType); yield return InjectionInfo.Create( propertyInfo.GetGetMethod(nonPublic: true), fixingMethod @@ -127,13 +127,13 @@ public override IEnumerable ProvideInjections() if (canWrite) { // inject constructor - var constructors = Get_Ctors(targetType); + var constructors = Get_Ctors(targetInfo.DeclaringType); var argtypes = new List(); foreach (var constructor in constructors) { Delegate rawAction = default; argtypes.Clear(); - argtypes.Add(targetType); + argtypes.Add(targetInfo.DeclaringType); foreach (var p in constructor.GetParameters()) { argtypes.Add(p.ParameterType); @@ -150,7 +150,7 @@ public override IEnumerable ProvideInjections() } var miCtorInst = s_miMetaConstructor.MakeGenericMethod(miInstAction); var fixingFunc = miCtorInst.Invoke(null, new object[]{ - (Action)fixedContructor,targetType,isStatic + (Action)fixedContructor,targetInfo.DeclaringType,isStatic }) as Delegate; yield return InjectionInfo.Create( constructor, @@ -159,7 +159,7 @@ public override IEnumerable ProvideInjections() ); void fixedContructor(object inst) { - SetMemberValue(targetMember, inst, GetContainerInst(memberType, targetType)); + SetMemberValue(targetInfo, inst, GetContainerInst(memberType, targetInfo.DeclaringType)); rawAction.GetType().GetMethod("Invoke").Invoke(rawAction, new[] { inst }); } } @@ -167,8 +167,8 @@ void fixedContructor(object inst) else { // inject get method - var propertyInfo = targetMember as PropertyInfo; - var fixingMethod = s_MetaMethodInfo.MakeGenericMethod(targetType, propertyInfo.PropertyType, targetType); + var propertyInfo = targetInfo as PropertyInfo; + var fixingMethod = s_MetaMethodInfo.MakeGenericMethod(targetInfo.DeclaringType, propertyInfo.PropertyType, targetInfo.DeclaringType); yield return InjectionInfo.Create( propertyInfo.GetGetMethod(nonPublic: true), fixingMethod diff --git a/Runtime/FixHelper.cs b/Runtime/FixHelper.cs index 3e1b9a1..c088be7 100644 --- a/Runtime/FixHelper.cs +++ b/Runtime/FixHelper.cs @@ -159,7 +159,7 @@ public static InjectionInfo[] GetAllInjections(Assembly[] assemblies = null) public static string[] GetAllInjectionSources() { var attributeSources = Retriever.GetAllAttributes() - .Select(attr => attr.targetType.Assembly); + .Select(attr => attr.targetInfo.Module.Assembly); var subtypeSources = Retriever.GetAllSubtypes() .Select(t => t.Assembly); return attributeSources.Concat(subtypeSources) diff --git a/package.json b/package.json index c5c95a9..7924fe9 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "hideInEditor": false, "author": "bbbirder <502100554@qq.com>", "dependencies": { - "com.bbbirder.directattribute": "1.1.8", + "com.bbbirder.directattribute": "2.0.0", "com.unity.nuget.mono-cecil": "1.10.2" }, "samples": [