【问题标题】:How can I use Type.GetType() with List'1[UnityEngine.Vector3]?如何将 Type.GetType() 与 List'1[UnityEngine.Vector3] 一起使用?
【发布时间】:2021-05-18 09:44:18
【问题描述】:

我目前正在使用:

    public static Type FindType(string qualifiedTypeName)
    {
        Type t = Type.GetType(qualifiedTypeName);

        if (t != null)
        {
            return t;
        }
        else
        {
            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                t = asm.GetType(qualifiedTypeName);
                if (t != null)
                    return t;
            }
            return null;
        }
      

感谢这篇文章中的@Alistar:Type.GetType not working
但是,当涉及到 UnityEngine 的 Vector3 列表时,即使这样也不起作用。
我知道您也可以通过在末尾添加“,UnityEngine”来包含相关程序集,但它不起作用。

编辑:
澄清一下,我正在尝试使用字符串值

"System.Collections.Generic.List`1[UnityEngine.Vector3]"

实际的列表类型可以是任何东西,并且想从这个字符串中找到实际的类型。这适用于常规列表和常规 var,但对于特殊列表类型,我会得到 null 结果。

有什么想法吗?

【问题讨论】:

  • 您的问题不清楚。您永远不会在程序集中找到构造的泛型类型已声明,即Assembly.GetType() 方法将返回该类型。他们不是这样工作的。这个问题绝对是XY Problem。你有一些其他更广泛的目标,你错误地决定需要反思来解决。你应该发布一个不同的问题,解释更广泛的目标是什么,到目前为止你已经尝试过什么,以及你具体需要什么帮助。

标签: c# unity3d types reflection gettype


【解决方案1】:

您提供的字符串不是AssemblyQualifiedName

看起来它只是Type.ToString的结果。

例如List<string>AssemblyQualifiedName 看起来像这样:

System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

List<Vector3> 会是

System.Collections.Generic.List`1[[UnityEngine.Vector3, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

【讨论】:

    猜你喜欢
    • 2013-10-14
    • 2020-11-07
    • 2021-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    相关资源
    最近更新 更多