Exemple #1
0
    //在这里注册消息返回后分发处理
    public void Init()
    {
        //返回我的解决方案中的所有程序集
        Type[] types = AppDomain.CurrentDomain.GetAssemblies()
                       .SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IHander))))
                       .ToArray();

        //相当于
        //public static IEnumerable<Type> GetType(Type interfaceType)
        //{
        //    foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
        //    {
        //        foreach (var type in assembly.GetTypes())
        //        {
        //            foreach (var t in type.GetInterfaces())
        //            {
        //                if (t == interfaceType)
        //                {
        //                    yield return type;
        //                    break;
        //                }
        //            }
        //        }
        //    }
        //}
        foreach (var item in types)
        {
            IHander obj = (IHander)Activator.CreateInstance(item);
            obj.RegisterMsg(_handers);
        }


        //按Json格式序列化
        //WebWorkData web = new WebWorkData() { ipAddress = ipAddress, urlPaths = mURLs };
        //var json = JsonConvert.SerializeObject(web, Formatting.Indented);
        //FileTool.CreateFile(Application.streamingAssetsPath + "/WebData.json", json);

        var str = FileTool.BytesToStr(FileTool.ReadFile(Application.streamingAssetsPath + "/WebData.json"));

        webWorkData = JsonConvert.DeserializeObject <WebWorkData>(str);
    }