예제 #1
0
    public void Init()
    {
        System.Reflection.Assembly asm = System.Reflection.Assembly.GetAssembly(typeof(BindPrefab));
        System.Type[] types            = asm.GetExportedTypes();

        foreach (Type type in types)
        {
            foreach (Attribute attribute in Attribute.GetCustomAttributes(type, true))
            {
                if (attribute is BindPrefab)
                {
                    BindPrefab data = attribute as BindPrefab;
                    BindUtil.Bind(data.Path, type);
                }
            }
        }
    }
    public void Init()
    {
        //获得BindPrefab所在的程序集
        Assembly assembly = Assembly.GetAssembly(typeof(BindPrefabAttribute));

        //获取程序集当中所有的公有类型
        Type[] types = assembly.GetExportedTypes();

        //遍历类型
        foreach (var type in types)
        {
            //遍历Type类型所拥有的特性 找到对应的特性
            foreach (Attribute attr in Attribute.GetCustomAttributes(type, true))
            {
                if (attr is BindPrefabAttribute)
                {
                    BindPrefabAttribute data = attr as BindPrefabAttribute;
                    BindUtil.Bind(data.Path, type);
                }
            }
        }
    }