Exemplo n.º 1
0
        private static void Init()
        {
            ScriptTypeMap.LoadClientTypeAssemblies();
            //Edited for .NET Core
            //Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            //AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(ScriptTypeMap.AppDomain_AssemblyLoad);
            //Assembly[] array = assemblies;
            //for (int i = 0; i < array.Length; i++)
            //{
            //    Assembly assembly = array[i];
            //    try
            //    {
            //        object[] customAttributes = assembly.GetCustomAttributes(typeof(ClientTypeAssemblyAttribute), false);
            //        if (customAttributes != null && customAttributes.Length != 0)
            //        {
            //            ScriptTypeMap.AddClientProxyAssembly(assembly);
            //        }
            //    }
            //    catch (Exception)
            //    {
            //    }
            //}

            // The above code seems to loop all loaded assemblies to check for the ClientTypeAssemblyAttribute
            // The below is how I have rewritten it for .NET Core
            // NOTE: I can't find a way to hook to something similiar to AppDomain.CurrentDomain.AssemblyLoad

            var currentAssembly = Assembly.GetEntryAssembly();
            var currentAssemblyClientTypeAttributes = currentAssembly.GetCustomAttribute <ClientTypeAssemblyAttribute>();
            var currentAssemblyReferencedAssemblies = currentAssembly.GetReferencedAssemblies();

            foreach (var assemblyName in currentAssemblyReferencedAssemblies)
            {
                try
                {
                    var assembly = Assembly.Load(assemblyName);

                    var customAttributes = assembly.GetCustomAttributes <ClientTypeAssemblyAttribute>();
                    if (customAttributes != null && customAttributes.Count() != 0)
                    {
                        ScriptTypeMap.AddClientProxyAssembly(assembly);
                    }
                }
                catch (Exception)
                {
                }
            }
        }