Exemplo n.º 1
0
        public static DocumentBase Create(
            string viewPath,
            object model       = null,
            Type baseClassType = null,
            bool forceCompile  = false)
        {
            viewPath = Path.GetFullPath(viewPath);

            if (!File.Exists(viewPath))
            {
                throw new ArgumentException($"Could not find the file '{viewPath}'", nameof(viewPath));
            }

            var viewLastWriteTime = new FileInfo(viewPath).LastWriteTime.ToString("s", System.Globalization.CultureInfo.InvariantCulture);

            if (baseClassType == null)
            {
                baseClassType = typeof(DocumentBase);
            }

            var baseClassName = baseClassType.Name;
            var modelTypeName = model?.GetType().Name ?? string.Empty;
            DocumentAssembly da;

            lock (AssembliesLock)
            {
                da = (DocumentAssembly)Assemblies[viewPath + viewLastWriteTime + baseClassName + modelTypeName];

                if (da == null || forceCompile)
                {
                    da = new DocumentAssembly(
                        viewPath,
                        baseClassType,
                        model?.GetType());

                    Assemblies[viewPath + viewLastWriteTime + baseClassName + modelTypeName] = da;
                }
            }

            var document = (DocumentBase)da.Instance();

            document.Init(viewPath, model);
            return(document);
        }
Exemplo n.º 2
0
        public static DocumentBase Create(
            string viewPath,
            object model       = null,
            Type baseClassType = null,
            bool forceCompile  = false)
        {
            viewPath = Path.GetFullPath(viewPath);

            if (baseClassType == null)
            {
                baseClassType = typeof(DocumentBase);
            }

            var baseClassName = baseClassType.Name;
            var modelTypeName = model?.GetType().Name ?? string.Empty;
            DocumentAssembly da;

            lock (AssembliesLock)
            {
                da = (DocumentAssembly)Assemblies[viewPath + baseClassName + modelTypeName];

                if (da == null || forceCompile)
                {
                    da = new DocumentAssembly(
                        viewPath,
                        baseClassType,
                        model?.GetType());

                    Assemblies[viewPath + baseClassName + modelTypeName] = da;
                }
            }

            var document = (DocumentBase)da.Instance();

            document.Init(viewPath, model);
            return(document);
        }