Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对于类型为泛型参数的成员,应该获取所有具体的实现而非基类声明的参数? #3

Open
xzaxzaazx opened this issue Jun 6, 2024 · 4 comments

Comments

@xzaxzaazx
Copy link

我在使用UnityInjection时,会导致无法注入类型为泛型参数的成员

@xzaxzaazx
Copy link
Author

或者都获取也行,可以手动排除含有泛型参数的成员

@labbbirder
Copy link
Owner

确认了下,是可以获取的。

class Student
{
    [DirectRetrieve]
    List<int> ints;

}
foreach(var a in Retriever.GetAllAttributes<DirectRetrieveAttribute>())
{
    print(a.targetInfo);
}
// outputs: System.Collections.Generic.List`1[System.Int32] ints

@xzaxzaazx
Copy link
Author

xzaxzaazx commented Jun 8, 2024

不是这种,是要带泛型参数(GenericParameter)的

public abstract class Singleton<T> where T : Singleton<T>{
     [DirectRetrieve]public static T instance;
}
public class Manager : Singeton<Manager>{}

debug的结果是只获取到了Singleton<T>的类型为T的Member,而没有获取到Singleton<Manager>的类型为Manager的Member,我个人认为应该这两个都获取一下,虽然前者一般用不到但可以简单地判断排除。

@labbbirder
Copy link
Owner

这种可以使用接口方式获取

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants