public TemplateLoader(Assembly assembly)
        {
            try
            {
                TemplateAssemblyDir = Path.GetDirectoryName(assembly.Location);
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);

                foreach (Type type in assembly.GetTypes())
                {
                    if (type.Name != "TemplateGen")
                    {
                        continue;
                    }

                    _ProjectNamespace    = type.Namespace;
                    _TemplateGenInstance = assembly.CreateInstance(type.FullName);
                    break;
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                string message = "";

                foreach (var tle in ex.LoaderExceptions)
                {
                    message += tle.Message + Environment.NewLine;
                }
                throw new Exception(message);
            }
            finally
            {
                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= CurrentDomain_ReflectionOnlyAssemblyResolve;
            }
            if (_TemplateGenInstance == null)
            {
                throw new ArgumentException("Could not find a class called TemplateGen in the given template assembly");
            }

            CurrentAssembly       = assembly;
            _ScriptRunnerInstance =
                (ScriptFunctionWrapper)CurrentAssembly.CreateInstance(_ProjectNamespace + ".ScriptFunctionWrapper");

            _TemplateGenInstance   = CurrentAssembly.CreateInstance(_ProjectNamespace + ".TemplateGen");
            _UserOptionsType       = CurrentAssembly.GetType(_ProjectNamespace + ".TemplateGen+UserOptions");
            _VirtualPropertiesType = CurrentAssembly.GetType(_ProjectNamespace + ".VirtualProperties");

            _LangAttributeType = CurrentAssembly.GetType(_ProjectNamespace + ".LanguageAttribute");
        }
Example #2
0
        public TemplateLoader(Assembly assembly)
        {
            try
            {
                TemplateAssemblyDir = Path.GetDirectoryName(assembly.Location);
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);

                foreach (Type type in assembly.GetTypes())
                {
                    if (type.Name != "TemplateGen") continue;

                    _ProjectNamespace = type.Namespace;
                    _TemplateGenInstance = assembly.CreateInstance(type.FullName);
                    break;
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                string message = "";

                foreach (var tle in ex.LoaderExceptions)
                {
                    message += tle.Message + Environment.NewLine;
                }
                throw new Exception(message);
            }
            finally
            {
                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= CurrentDomain_ReflectionOnlyAssemblyResolve;
            }
            if (_TemplateGenInstance == null)
                throw new ArgumentException("Could not find a class called TemplateGen in the given template assembly");

            CurrentAssembly = assembly;
            _ScriptRunnerInstance =
                (ScriptFunctionWrapper)CurrentAssembly.CreateInstance(_ProjectNamespace + ".ScriptFunctionWrapper");

            _TemplateGenInstance = CurrentAssembly.CreateInstance(_ProjectNamespace + ".TemplateGen");
            _UserOptionsType = CurrentAssembly.GetType(_ProjectNamespace + ".TemplateGen+UserOptions");
            _VirtualPropertiesType = CurrentAssembly.GetType(_ProjectNamespace + ".VirtualProperties");

            _LangAttributeType = CurrentAssembly.GetType(_ProjectNamespace + ".LanguageAttribute");
        }