当前位置: 首页 > news >正文

C#反射执行方法返回List,怎么获取List

baidu

C# 反射 获取 list 字段

示例代码:

private Type CheckTypeString(string typeStr)
        {
            Type ret = Type.GetType(typeStr + ", UnityEditor");
            if (ret == null)
            {
                ret = Type.GetType("UnityEditor." + typeStr + ", UnityEditor");
            }

            if (ret == null)
            {
                UnityEngine.Debug.Log(string.Format("Cannot find {0}", typeStr));
                return null;
            }

            return ret;
        }

        protected System.Reflection.MethodInfo CheckTypeMethod(Type type, string methodName)
        {
            return type.GetMethod(methodName);
        }

        protected System.Reflection.FieldInfo CheckTypeField(Type type, string fieldName)
        {
            return type.GetField(
                fieldName,
                System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic
                );
        }

        protected void TestAnimEditor()
        {
            Type typeAnimEditor = CheckTypeString("AnimEditor");
            if (null != typeAnimEditor)
            {
                System.Reflection.MethodInfo method = CheckTypeMethod(typeAnimEditor, "GetAllAnimationWindows");
                if (null != method)
                {
                    object obj = method.Invoke(null, null);
                    //List<object> objectList = ret as List<object>;
                    //IEnumerable<System.Object> list = ret as IEnumerable<System.Object>;
                    System.Collections.IEnumerable objEnm = obj as System.Collections.IEnumerable;
                    System.Collections.IEnumerator curIte = objEnm.GetEnumerator();
                    curIte.MoveNext();
                    object curAnimEditor = curIte.Current;


                    System.Reflection.FieldInfo fieldState = CheckTypeField(typeAnimEditor, "m_State");
                    if (null != fieldState)
                    {
                        object fieldValueState = fieldState.GetValue(curAnimEditor);

                        Type animationWindowStateType = CheckTypeString("AnimationWindowState");
                        if (null != animationWindowStateType)
                        {
                            System.Reflection.FieldInfo fieldControl = CheckTypeField(animationWindowStateType, "m_ControlInterface");
                            if (null != fieldControl)
                            {
                                object fieldValueControl = fieldControl.GetValue(fieldValueState);

                                Type animationWindowControlType = CheckTypeString("AnimationWindowControl");
                                if (null != animationWindowControlType)
                                {
                                    System.Reflection.FieldInfo fieldAnimationClip = CheckTypeField(animationWindowControlType, "activeAnimationClip");

                                    if (null != fieldAnimationClip)
                                    {
                                        object animationClipValue = fieldAnimationClip.GetValue(animationWindowControlType);
                                        AnimationClip animationClip = animationClipValue as AnimationClip;
                                        UnityEngine.Debug.Log(string.Format("Cannot find {0}", ""));
                                    }
                                }
                            }
                        }
                    }

                    UnityEngine.Debug.Log(string.Format("Cannot find {0}", ""));
                }
            }
        }

        protected void TestAnimEditorV2()
        {
            Type typeAnimEditor = CheckTypeString("AnimEditor");

            if (null != typeAnimEditor)
            {
                System.Reflection.MethodInfo method = CheckTypeMethod(typeAnimEditor, "GetAllAnimationWindows");
                if (null != method)
                {
                    object obj = method.Invoke(null, null);
                    //List<object> objectList = ret as List<object>;
                    //IEnumerable<System.Object> list = ret as IEnumerable<System.Object>;
                    System.Collections.IEnumerable objEnm = obj as System.Collections.IEnumerable;
                    System.Collections.IEnumerator curIte = objEnm.GetEnumerator();
                    curIte.MoveNext();
                    object curAnimEditor = curIte.Current;


                    System.Reflection.FieldInfo fieldState = CheckTypeField(typeAnimEditor, "state");
                    if (null != fieldState)
                    {
                        object fieldValueState = fieldState.GetValue(curAnimEditor);

                        Type animationWindowStateType = CheckTypeString("AnimationWindowState");
                        if (null != animationWindowStateType)
                        {
                            System.Reflection.FieldInfo fieldAnimationClip = CheckTypeField(animationWindowStateType, "activeAnimationClip");

                            if (null != fieldAnimationClip)
                            {
                                object animationClipValue = fieldAnimationClip.GetValue(typeof(AnimationClip));
                                AnimationClip animationClip = animationClipValue as AnimationClip;
                                UnityEngine.Debug.Log(string.Format("Cannot find {0}", ""));
                            }
                        }
                    }

                    UnityEngine.Debug.Log(string.Format("Cannot find {0}", ""));
                }
            }
        }

相关文章:

  • C#通过反射获取相应的字段和值
  • pbrt-perspective-we(Weight emit)
  • pbrt gamma
  • Unity Android 宏定义是 UNITY_ANDROID 不是 UNITY_Android
  • Unity 与 Android 互调用
  • Unity Windows 编辑器下,模拟 Android
  • Unity 转换平台
  • 生成特定分贝的音频波形
  • 声音分贝的概念,dBSPL.dBm,dBu,dBV,dBFS
  • 获取PCM音频数据的声音分贝值
  • 如何从wav数据判断音量的高低?
  • Audio 音频采样和音量
  • AudioClip 参数解析
  • Unity 导入 KeyFrame 动画后,看不到动画
  • Unity3D中Blendshapes之间的过渡方式
  • SegmentFault for Android 3.0 发布
  • 【5+】跨webview多页面 触发事件(二)
  • 【挥舞JS】JS实现继承,封装一个extends方法
  • 2017-09-12 前端日报
  • CSS 提示工具(Tooltip)
  • Essential Studio for ASP.NET Web Forms 2017 v2,新增自定义树形网格工具栏
  • java8-模拟hadoop
  • MySQL-事务管理(基础)
  • Python爬虫--- 1.3 BS4库的解析器
  • session共享问题解决方案
  • 从零开始的无人驾驶 1
  • 理解 C# 泛型接口中的协变与逆变(抗变)
  • 力扣(LeetCode)22
  • 盘点那些不知名却常用的 Git 操作
  • 普通函数和构造函数的区别
  • 前端每日实战 2018 年 7 月份项目汇总(共 29 个项目)
  • 前端设计模式
  • 实战|智能家居行业移动应用性能分析
  • 网页视频流m3u8/ts视频下载
  • 问:在指定的JSON数据中(最外层是数组)根据指定条件拿到匹配到的结果
  • 问题之ssh中Host key verification failed的解决
  • 源码安装memcached和php memcache扩展
  • 源码之下无秘密 ── 做最好的 Netty 源码分析教程
  • LIGO、Virgo第三轮探测告捷,同时探测到一对黑洞合并产生的引力波事件 ...
  • TPG领衔财团投资轻奢珠宝品牌APM Monaco
  • 宾利慕尚创始人典藏版国内首秀,2025年前实现全系车型电动化 | 2019上海车展 ...
  • ​Java并发新构件之Exchanger
  • #stm32驱动外设模块总结w5500模块
  • #微信小程序:微信小程序常见的配置传旨
  • #我与Java虚拟机的故事#连载18:JAVA成长之路
  • $GOPATH/go.mod exists but should not goland
  • (02)Hive SQL编译成MapReduce任务的过程
  • (11)MATLAB PCA+SVM 人脸识别
  • (20050108)又读《平凡的世界》
  • (3)选择元素——(17)练习(Exercises)
  • (切换多语言)vantUI+vue-i18n进行国际化配置及新增没有的语言包
  • (转)清华学霸演讲稿:永远不要说你已经尽力了
  • .[hudsonL@cock.li].mkp勒索加密数据库完美恢复---惜分飞
  • .【机器学习】隐马尔可夫模型(Hidden Markov Model,HMM)
  • .bat批处理出现中文乱码的情况