Skip to content

Commit

Permalink
chore: update dependency dra
Browse files Browse the repository at this point in the history
  • Loading branch information
labbbirder committed Apr 1, 2024
1 parent ffa1721 commit 090dbc9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Runtime/ClassicalUsages/DecoratorAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public abstract partial class DecoratorAttribute : InjectionAttribute
/// <typeparam name="AsyncStateMachineAttribute"></typeparam>
/// <returns></returns>
public bool IsAsyncMethod
=> m_IsAsyncMethod ??= targetMember.GetCustomAttribute<AsyncStateMachineAttribute>() != null;
=> m_IsAsyncMethod ??= targetInfo.GetCustomAttribute<AsyncStateMachineAttribute>() != null;

public override IEnumerable<InjectionInfo> 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;

Expand Down
28 changes: 14 additions & 14 deletions Runtime/ClassicalUsages/SimpleDIAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public override IEnumerable<InjectionInfo> 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)
{
Expand All @@ -108,14 +108,14 @@ public override IEnumerable<InjectionInfo> 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
Expand All @@ -127,13 +127,13 @@ public override IEnumerable<InjectionInfo> ProvideInjections()
if (canWrite)
{
// inject constructor
var constructors = Get_Ctors(targetType);
var constructors = Get_Ctors(targetInfo.DeclaringType);
var argtypes = new List<Type>();
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);
Expand All @@ -150,7 +150,7 @@ public override IEnumerable<InjectionInfo> ProvideInjections()
}
var miCtorInst = s_miMetaConstructor.MakeGenericMethod(miInstAction);
var fixingFunc = miCtorInst.Invoke(null, new object[]{
(Action<object>)fixedContructor,targetType,isStatic
(Action<object>)fixedContructor,targetInfo.DeclaringType,isStatic
}) as Delegate;
yield return InjectionInfo.Create(
constructor,
Expand All @@ -159,16 +159,16 @@ public override IEnumerable<InjectionInfo> 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 });
}
}
}
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
Expand Down
2 changes: 1 addition & 1 deletion Runtime/FixHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static InjectionInfo[] GetAllInjections(Assembly[] assemblies = null)
public static string[] GetAllInjectionSources()
{
var attributeSources = Retriever.GetAllAttributes<InjectionAttribute>()
.Select(attr => attr.targetType.Assembly);
.Select(attr => attr.targetInfo.Module.Assembly);
var subtypeSources = Retriever.GetAllSubtypes<IInjection>()
.Select(t => t.Assembly);
return attributeSources.Concat(subtypeSources)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"hideInEditor": false,
"author": "bbbirder <[email protected]>",
"dependencies": {
"com.bbbirder.directattribute": "1.1.8",
"com.bbbirder.directattribute": "2.0.0",
"com.unity.nuget.mono-cecil": "1.10.2"
},
"samples": [
Expand Down

0 comments on commit 090dbc9

Please sign in to comment.