Assembly.GetExecutingAssembly()

作者:追风剑情 发布于:2018-1-15 18:05 分类:C#

示例

using UnityEngine;
using System;
using System.Linq;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;

namespace my_test {
    public class Test1 : MonoBehaviour {

        void Start()
        {
            PrintExecutingAssembly();
        }

        private void PrintExecutingAssembly()
        {
            //得到当前执行代码所在程序集中命名空间为my_test中的类型定义
            List<Type> types = (from type in Assembly.GetExecutingAssembly().GetTypes()
                                where type.Namespace == "my_test"
                                select type).ToList();
            for (int i = 0; i < types.Count; i++)
                Debug.Log(types[i].FullName);
        }
    }

    public class Test2
    {
        private class Test2_2 { }
    }

    public struct Struct1 { }

    public enum Enum1 { }
}

运行测试

11111.png

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号