コード例 #1
0
        public RazorTemplatingHost(Type baseType)
            : base(new CSharpRazorCodeLanguage())
        {
            if (baseType == null)
            {
                throw new ArgumentNullException(nameof(baseType));
            }

            DefaultBaseClass = baseType.FullName;

            //ToDo: Why Do I need templateTypeName? Do I need other parameters?
            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "ExecuteAsync",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "",
                generatedTagHelperContext: new GeneratedTagHelperContext())
            {
            };

            foreach (var ns in _defaultNamespaces)
            {
                NamespaceImports.Add(ns);
            }
        }
コード例 #2
0
        public MvcRazorHost(string baseType)
            : base(new CSharpRazorCodeLanguage())
        {
            // TODO: this needs to flow from the application rather than being initialized here.
            // Tracked by #774
            _hostOptions          = new MvcRazorHostOptions();
            _baseType             = baseType;
            DefaultBaseClass      = baseType + '<' + _hostOptions.DefaultModel + '>';
            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "ExecuteAsync",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "HelperResult",
                defineSectionMethodName: "DefineSection")
            {
                ResolveUrlMethodName = "Href"
            };

            foreach (var ns in _defaultNamespaces)
            {
                NamespaceImports.Add(ns);
            }
        }
コード例 #3
0
ファイル: MvcRazorHost.cs プロジェクト: gitter-badger/Mvc-4
        internal MvcRazorHost(ICodeTreeCache codeTreeCache, RazorPathNormalizer pathNormalizer)
            : base(new CSharpRazorCodeLanguage())
        {
            _pathNormalizer = pathNormalizer;
            _baseType       = BaseType;
            _codeTreeCache  = codeTreeCache;

            TagHelperDescriptorResolver = new TagHelperDescriptorResolver();
            DefaultBaseClass            = BaseType + "<" + DefaultModel + ">";
            DefaultNamespace            = "Asp";
            // Enable instrumentation by default to allow precompiled views to work with BrowserLink.
            EnableInstrumentation = true;
            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "ExecuteAsync",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "Microsoft.AspNet.Mvc.Razor.HelperResult",
                defineSectionMethodName: "DefineSection",
                generatedTagHelperContext: new GeneratedTagHelperContext
            {
                ExecutionContextTypeName      = typeof(TagHelperExecutionContext).FullName,
                ExecutionContextAddMethodName = nameof(TagHelperExecutionContext.Add),
                ExecutionContextAddTagHelperAttributeMethodName =
                    nameof(TagHelperExecutionContext.AddTagHelperAttribute),
                ExecutionContextAddHtmlAttributeMethodName = nameof(TagHelperExecutionContext.AddHtmlAttribute),
                ExecutionContextOutputPropertyName         = nameof(TagHelperExecutionContext.Output),

                RunnerTypeName           = typeof(TagHelperRunner).FullName,
                RunnerRunAsyncMethodName = nameof(TagHelperRunner.RunAsync),

                ScopeManagerTypeName        = typeof(TagHelperScopeManager).FullName,
                ScopeManagerBeginMethodName = nameof(TagHelperScopeManager.Begin),
                ScopeManagerEndMethodName   = nameof(TagHelperScopeManager.End),

                TagHelperContentTypeName = nameof(TagHelperContent),

                // Can't use nameof because RazorPage is not accessible here.
                CreateTagHelperMethodName            = "CreateTagHelper",
                StartTagHelperWritingScopeMethodName = "StartTagHelperWritingScope",
                EndTagHelperWritingScopeMethodName   = "EndTagHelperWritingScope",

                WriteTagHelperAsyncMethodName   = "WriteTagHelperAsync",
                WriteTagHelperToAsyncMethodName = "WriteTagHelperToAsync",

                // Can't use nameof because IHtmlHelper is (also) not accessible here.
                MarkAsHtmlEncodedMethodName = HtmlHelperPropertyName + ".Raw",
            })
            {
                ResolveUrlMethodName   = "Href",
                BeginContextMethodName = "BeginContext",
                EndContextMethodName   = "EndContext"
            };

            foreach (var ns in _defaultNamespaces)
            {
                NamespaceImports.Add(ns);
            }
        }
コード例 #4
0
        public MvcWebPageRazorHost(string virtualPath, string physicalPath)
            : base(virtualPath, physicalPath)
        {
            RegisterSpecialFile(RazorViewEngine.ViewStartFileName, typeof(ViewStartPage));

            DefaultPageBaseClass = typeof(WebViewPage).FullName;

            NamespaceImports.Add("System.Threading.Tasks");
            var context = GeneratedClassContext;

            if (!String.IsNullOrEmpty(context.ExecuteMethodName))
            {
                GeneratedClassContext = new GeneratedClassContext(context.ExecuteMethodName + "Async",
                                                                  context.WriteMethodName,
                                                                  context.WriteLiteralMethodName,
                                                                  context.WriteToMethodName,
                                                                  context.WriteLiteralToMethodName,
                                                                  context.TemplateTypeName,
                                                                  context.DefineSectionMethodName,
                                                                  context.BeginContextMethodName,
                                                                  context.EndContextMethodName)
                {
                    ResolveUrlMethodName = context.ResolveUrlMethodName
                };
            }
            // REVIEW get rid of the namespace import to not force additional references in default MVC projects
            GetRidOfNamespace("System.Web.WebPages.Html");
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of <see cref="MvcRazorHost"/> using the specified <paramref name="fileSystem"/>.
        /// </summary>
        /// <param name="fileSystem">A <see cref="IFileSystem"/> rooted at the application base path.</param>
        protected internal MvcRazorHost([NotNull] IFileSystem fileSystem)
            : base(new CSharpRazorCodeLanguage())
        {
            _fileSystem = fileSystem;
            _baseType   = BaseType;

            DefaultBaseClass      = BaseType + '<' + DefaultModel + '>';
            DefaultNamespace      = "Asp";
            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "ExecuteAsync",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "Microsoft.AspNet.Mvc.Razor.HelperResult",
                defineSectionMethodName: "DefineSection")
            {
                ResolveUrlMethodName = "Href"
            };

            foreach (var ns in _defaultNamespaces)
            {
                NamespaceImports.Add(ns);
            }
        }
コード例 #6
0
        public OpenRastaRazorHost(RazorCodeLanguage codeLanguage)
        {
            NamespaceImports.Add("System");
            NamespaceImports.Add("System.Collections.Generic");
            NamespaceImports.Add("System.IO");
            NamespaceImports.Add("System.Linq");
            NamespaceImports.Add("System.Net");
            NamespaceImports.Add("System.Web");
            //NamespaceImports.Add("System.Web.Helpers");
            NamespaceImports.Add("System.Web.Security");
            NamespaceImports.Add("System.Web.UI");
            NamespaceImports.Add("System.Web.WebPages");

            DefaultNamespace      = WebDefaultNamespace;
            GeneratedClassContext = new GeneratedClassContext(GeneratedClassContext.DefaultExecuteMethodName,
                                                              GeneratedClassContext.DefaultWriteMethodName,
                                                              GeneratedClassContext.DefaultWriteLiteralMethodName,
                                                              WriteToMethodName,
                                                              WriteLiteralToMethodName,
                                                              TemplateTypeName,
                                                              DefineSectionMethodName);
            DefaultBaseClass        = typeof(RazorViewBase <>).AssemblyQualifiedName;
            DefaultDebugCompilation = true;
            CodeLanguage            = codeLanguage;
        }
コード例 #7
0
        private WebPageRazorHost()
        {
            NamespaceImports.Add("System");
            NamespaceImports.Add("System.Collections.Generic");
            NamespaceImports.Add("System.IO");
            NamespaceImports.Add("System.Linq");
            NamespaceImports.Add("System.Net");
            NamespaceImports.Add("System.Web");
            NamespaceImports.Add("System.Web.Helpers");
            NamespaceImports.Add("System.Web.Security");
            NamespaceImports.Add("System.Web.UI");
            NamespaceImports.Add("System.Web.WebPages");
            NamespaceImports.Add("System.Web.WebPages.Html");

            DefaultNamespace      = WebDefaultNamespace;
            GeneratedClassContext = new GeneratedClassContext(GeneratedClassContext.DefaultExecuteMethodName,
                                                              GeneratedClassContext.DefaultWriteMethodName,
                                                              GeneratedClassContext.DefaultWriteLiteralMethodName,
                                                              WriteToMethodName,
                                                              WriteLiteralToMethodName,
                                                              TemplateTypeName,
                                                              DefineSectionMethodName);
            DefaultPageBaseClass    = PageBaseClass;
            DefaultDebugCompilation = true;
        }
コード例 #8
0
ファイル: MvcRazorHost.cs プロジェクト: gitter-badger/Wyam
        internal MvcRazorHost(Type basePageType)
            : base(new CSharpRazorCodeLanguage())
        {
            DefaultBaseClass      = basePageType == null ? DefaultBaseType : basePageType.FullName;
            DefaultNamespace      = "Wyam.Modules.Razor";
            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "ExecuteAsync",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "Wyam.Modules.Razor.Microsoft.AspNet.Mvc.Razor.HelperResult",
                defineSectionMethodName: "DefineSection",
                generatedTagHelperContext: null)
            {
                ResolveUrlMethodName   = "Href",
                BeginContextMethodName = "BeginContext",
                EndContextMethodName   = "EndContext"
            };

            foreach (var ns in _defaultNamespaces)
            {
                NamespaceImports.Add(ns);
            }
        }
コード例 #9
0
        private WebPageRazorHost()
        {
            NamespaceImports.Add("System");
            NamespaceImports.Add("System.Collections.Generic");
            NamespaceImports.Add("System.IO");
            NamespaceImports.Add("System.Linq");
            NamespaceImports.Add("System.Net");
            NamespaceImports.Add("System.Web");
            NamespaceImports.Add("System.Web.Helpers");
            NamespaceImports.Add("System.Web.Security");
            NamespaceImports.Add("System.Web.UI");
            NamespaceImports.Add("System.Web.WebPages");
            NamespaceImports.Add("System.Web.WebPages.Html");

            RegisterSpecialFile(ApplicationStartFileName, typeof(ApplicationStartPage));
            RegisterSpecialFile(PageStartFileName, typeof(StartPage));
            DefaultNamespace      = WebDefaultNamespace;
            GeneratedClassContext = new GeneratedClassContext(GeneratedClassContext.DefaultExecuteMethodName,
                                                              GeneratedClassContext.DefaultWriteMethodName,
                                                              GeneratedClassContext.DefaultWriteLiteralMethodName,
                                                              WriteToMethodName,
                                                              WriteLiteralToMethodName,
                                                              TemplateTypeName,
                                                              DefineSectionMethodName)
            {
                ResolveUrlMethodName = ResolveUrlMethodName
            };
            DefaultPageBaseClass    = PageBaseClass;
            DefaultDebugCompilation = true;
        }
コード例 #10
0
        public PageRazorEngineHost()
            : base(new CSharpRazorCodeLanguage())
        {
            DefaultBaseClass = typeof(Page).FullName;

            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "RenderAsync",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "Microsoft.AspNetCore.Mvc.Razor.HelperResult",
                defineSectionMethodName: "DefineSection",
                generatedTagHelperContext: new GeneratedTagHelperContext
            {
                ExecutionContextTypeName      = typeof(TagHelperExecutionContext).FullName,
                ExecutionContextAddMethodName = nameof(TagHelperExecutionContext.Add),
                ExecutionContextAddTagHelperAttributeMethodName =
                    nameof(TagHelperExecutionContext.AddTagHelperAttribute),
                ExecutionContextAddHtmlAttributeMethodName = nameof(TagHelperExecutionContext.AddHtmlAttribute),
                ExecutionContextOutputPropertyName         = nameof(TagHelperExecutionContext.Output),

                RunnerTypeName           = typeof(TagHelperRunner).FullName,
                RunnerRunAsyncMethodName = nameof(TagHelperRunner.RunAsync),

                ScopeManagerTypeName        = typeof(TagHelperScopeManager).FullName,
                ScopeManagerBeginMethodName = nameof(TagHelperScopeManager.Begin),
                ScopeManagerEndMethodName   = nameof(TagHelperScopeManager.End),

                TagHelperContentTypeName = typeof(TagHelperContent).FullName,

                // Can't use nameof because RazorPage is not accessible here.
                CreateTagHelperMethodName = "CreateTagHelper",
                FormatInvalidIndexerAssignmentMethodName = "InvalidTagHelperIndexerAssignment",
                StartTagHelperWritingScopeMethodName     = "StartTagHelperWritingScope",
                EndTagHelperWritingScopeMethodName       = "EndTagHelperWritingScope",
                BeginWriteTagHelperAttributeMethodName   = "BeginWriteTagHelperAttribute",
                EndWriteTagHelperAttributeMethodName     = "EndWriteTagHelperAttribute",

                // Can't use nameof because IHtmlHelper is (also) not accessible here.
                MarkAsHtmlEncodedMethodName           = "Html.Raw",
                BeginAddHtmlAttributeValuesMethodName = "BeginAddHtmlAttributeValues",
                EndAddHtmlAttributeValuesMethodName   = "EndAddHtmlAttributeValues",
                AddHtmlAttributeValueMethodName       = "AddHtmlAttributeValue",
                HtmlEncoderPropertyName = "HtmlEncoder",
                TagHelperContentGetContentMethodName            = nameof(TagHelperContent.GetContent),
                TagHelperOutputIsContentModifiedPropertyName    = nameof(TagHelperOutput.IsContentModified),
                TagHelperOutputContentPropertyName              = nameof(TagHelperOutput.Content),
                ExecutionContextSetOutputContentAsyncMethodName = nameof(TagHelperExecutionContext.SetOutputContentAsync),
                TagHelperAttributeValuePropertyName             = nameof(TagHelperAttribute.Value),
            })
            {
                BeginContextMethodName = "BeginContext",
                EndContextMethodName   = "EndContext"
            };
        }
コード例 #11
0
ファイル: MvcRazorHost.cs プロジェクト: ycrumeyrolle/Mvc
        /// <summary>
        /// Initializes a new instance of <see cref="MvcRazorHost"/> using the specified <paramref name="fileSystem"/>.
        /// </summary>
        /// <param name="fileSystem">A <see cref="IFileSystem"/> rooted at the application base path.</param>
        public MvcRazorHost(IFileSystem fileSystem)
            : base(new CSharpRazorCodeLanguage())
        {
            _fileSystem = fileSystem;
            _baseType   = BaseType;

            TagHelperDescriptorResolver = new TagHelperDescriptorResolver();
            DefaultBaseClass            = BaseType + '<' + DefaultModel + '>';
            DefaultNamespace            = "Asp";
            // Enable instrumentation by default to allow precompiled views to work with BrowserLink.
            EnableInstrumentation = true;
            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "ExecuteAsync",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "Microsoft.AspNet.Mvc.Razor.HelperResult",
                defineSectionMethodName: "DefineSection",
                generatedTagHelperContext: new GeneratedTagHelperContext
            {
                ExecutionContextTypeName      = typeof(TagHelperExecutionContext).FullName,
                ExecutionContextAddMethodName = nameof(TagHelperExecutionContext.Add),
                ExecutionContextAddTagHelperAttributeMethodName =
                    nameof(TagHelperExecutionContext.AddTagHelperAttribute),
                ExecutionContextAddHtmlAttributeMethodName = nameof(TagHelperExecutionContext.AddHtmlAttribute),
                ExecutionContextOutputPropertyName         = nameof(TagHelperExecutionContext.Output),

                RunnerTypeName           = typeof(TagHelperRunner).FullName,
                RunnerRunAsyncMethodName = nameof(TagHelperRunner.RunAsync),

                ScopeManagerTypeName        = typeof(TagHelperScopeManager).FullName,
                ScopeManagerBeginMethodName = nameof(TagHelperScopeManager.Begin),
                ScopeManagerEndMethodName   = nameof(TagHelperScopeManager.End),

                OutputGenerateStartTagMethodName = nameof(TagHelperOutput.GenerateStartTag),
                OutputGenerateContentMethodName  = nameof(TagHelperOutput.GenerateContent),
                OutputGenerateEndTagMethodName   = nameof(TagHelperOutput.GenerateEndTag),

                // Can't use nameof because RazorPage is not accessible here.
                CreateTagHelperMethodName   = "CreateTagHelper",
                StartWritingScopeMethodName = "StartWritingScope",
                EndWritingScopeMethodName   = "EndWritingScope",
            })
            {
                ResolveUrlMethodName   = "Href",
                BeginContextMethodName = "BeginContext",
                EndContextMethodName   = "EndContext"
            };

            foreach (var ns in _defaultNamespaces)
            {
                NamespaceImports.Add(ns);
            }
        }
コード例 #12
0
        private const string TemplateTypeName = "";             // used when @helper <func> {} is defined. not currently implemented

        private TemplateRazorEngineHost()
        {
            GeneratedClassContext = new GeneratedClassContext(GeneratedClassContext.DefaultExecuteMethodName,
                                                              GeneratedClassContext.DefaultWriteMethodName,
                                                              GeneratedClassContext.DefaultWriteLiteralMethodName,
                                                              WriteToMethodName,
                                                              WriteLiteralToMethodName,
                                                              TemplateTypeName,
                                                              DefineSectionMethodName,
                                                              BeginContextMethodName,
                                                              EndContextMethodName);
        }
コード例 #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RazorEngineHost"/> class.
        /// </summary>
        /// <param name="language">The language.</param>
        public RazorEngineHost(RazorCodeLanguage language) : base(language)
        {
            this.DefaultBaseClass = typeof(RazorViewPage).FullName;
            this.DefaultNamespace = "RazorOutput";
            this.DefaultClassName = "RazorView";

            var context = new GeneratedClassContext("Execute", "Write", "WriteLiteral", "WriteTo", "WriteLiteralTo", null, "DefineSection");

            context.ResolveUrlMethodName = "ResolveUrl";

            this.GeneratedClassContext = context;
        }
コード例 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyRazorEngineHost"/> class.
        /// </summary>
        public NancyRazorEngineHost(RazorCodeLanguage language, RazorAssemblyProvider razorAssemblyProvider)
            : base(language)
        {
            this.razorAssemblyProvider = razorAssemblyProvider;
            this.DefaultBaseClass      = typeof(NancyRazorViewBase).FullName;
            this.DefaultNamespace      = "RazorOutput";
            this.DefaultClassName      = "RazorView";

            var context = new GeneratedClassContext("Execute", "Write", "WriteLiteral", "WriteTo", "WriteLiteralTo",
                                                    typeof(HelperResult).FullName, "DefineSection");

            context.ResolveUrlMethodName = "ResolveUrl";

            this.GeneratedClassContext = context;
        }
コード例 #15
0
ファイル: RazorPadHost.cs プロジェクト: yousafgill/RazorPad
        public RazorPadHost(RazorCodeLanguage language = null)
        {
// ReSharper disable DoNotCallOverridableMethodsInConstructor
            DefaultBaseClass      = typeof(TemplateBase).FullName;
            DefaultClassName      = "CompiledTemplate";
            DefaultNamespace      = "RazorPad.Runtime";
            CodeLanguage          = language;
            GeneratedClassContext = new GeneratedClassContext(
                GeneratedClassContext.DefaultExecuteMethodName,
                GeneratedClassContext.DefaultWriteMethodName,
                GeneratedClassContext.DefaultWriteLiteralMethodName,
                "WriteTo", "WriteLiteralTo",
                typeof(HelperResult).FullName);
// ReSharper restore DoNotCallOverridableMethodsInConstructor
        }
コード例 #16
0
        public PreprocessedRazorHost(string fullPath) : base(RazorCodeLanguage.GetLanguageByExtension(".cshtml"))
        {
            if (fullPath == null)
            {
                throw new ArgumentNullException("fullPath");
            }

            FullPath          = fullPath;
            _codeDomProvider  = new Microsoft.CSharp.CSharpCodeProvider();
            DefaultNamespace  = "ASP";
            EnableLinePragmas = true;
            StaticHelpers     = true;

            GeneratedClassContext = new GeneratedClassContext(
                GeneratedClassContext.DefaultExecuteMethodName,
                GeneratedClassContext.DefaultWriteMethodName,
                GeneratedClassContext.DefaultWriteLiteralMethodName,
                "WriteTo",
                "WriteLiteralTo",
                "Action<System.IO.TextWriter>",
                "DefineSection",
                "BeginContext",
                "EndContext"
                )
            {
                ResolveUrlMethodName = "Href"
            };

            codeGeneratorOptions = new CodeGeneratorOptions {
                // HACK: we use true, even though razor uses false, to work around a mono bug where it omits the
                // line ending after "#line hidden", resulting in the unparseable "#line hiddenpublic"
                BlankLinesBetweenMembers = true,
                BracingStyle             = "C",
                // matches Razor built-in settings
                IndentString = String.Empty,
            };

            foreach (var import in defaultImports)
            {
                NamespaceImports.Add(import);
            }
        }
コード例 #17
0
        private Type getViewType(RazorTemplate descriptor)
        {
            var className             = ParserHelpers.SanitizeClassName(descriptor.ViewPath);
            var baseTemplateType      = _razorEngineSettings.BaseTemplateType;
            var generatedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral", "WriteTo", "WriteLiteralTo",
                                                                  "FubuMVC.Razor.Rendering.TemplateHelper", "DefineSection");
            var codeLanguage = RazorCodeLanguageFactory.Create(descriptor.FilePath.FileExtension());
            var host         = new RazorEngineHost(codeLanguage)
            {
                DefaultBaseClass      = baseTemplateType.FullName,
                DefaultNamespace      = "FubuMVC.Razor.GeneratedTemplates",
                GeneratedClassContext = generatedClassContext
            };

            host.NamespaceImports.UnionWith(_commonViewNamespaces.Namespaces);

            var results = _templateGenerator.GenerateCode(descriptor, className, host);

            return(_templateCompiler.Compile(className, results.GeneratedCode, host));
        }
コード例 #18
0
ファイル: RazorCompile.cs プロジェクト: lanicon/RazorEngine
        private static RazorTemplateEngine CreateHost(Type basetype, string generatedNamespace, string generatedClass)
        {
            Type baseClassType = basetype;

            RazorEngineHost host = new RazorEngineHost(new CSharpRazorCodeLanguage());

            host.DefaultBaseClass = baseClassType.FullName;
            host.DefaultClassName = generatedClass;
            host.DefaultNamespace = generatedNamespace;
            GeneratedClassContext gcc = host.GeneratedClassContext;

            gcc.DefineSectionMethodName = "DefineSection";
            host.GeneratedClassContext  = gcc;
            foreach (string ns in ReferencedNamespaces)
            {
                host.NamespaceImports.Add(ns);
            }

            return(new RazorTemplateEngine(host));
        }
コード例 #19
0
        public RazorTemplatingHost([NotNull] Type baseType)
            : base(new CSharpRazorCodeLanguage())
        {
            DefaultBaseClass = baseType.FullName;

            //ToDo: Why Do I need templateTypeName? Do I need other parameters?
            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "ExecuteAsync",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "")
            {
            };

            foreach (var ns in _defaultNamespaces)
            {
                NamespaceImports.Add(ns);
            }
        }
コード例 #20
0
ファイル: MvcRazorHost.cs プロジェクト: vathuluri/Mvc
        public MvcRazorHost()
            : base(new CSharpRazorCodeLanguage())
        {
            DefaultBaseClass      = typeof(RazorView).FullName;
            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "Execute",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "Template",
                defineSectionMethodName: "DefineSection")
            {
                ResolveUrlMethodName = "Href"
            };

            foreach (var ns in _namespaces)
            {
                NamespaceImports.Add(ns);
            }
        }
コード例 #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XiptonEngineHost"/> class.
        /// </summary>
        /// <param name="config">The config holds all settings that are needed to initialzie the host.</param>
        public XiptonEngineHost(RazorConfig config)
            : base(config.Templates.Language)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            _defaultNamespace = "Xipton.Razor.Generated";
            _config           = config.AsReadonly();
            _defaultBaseClass = _config.Templates.NonGenericBaseTypeName;
            _namespaceImports = new HashSet <string>();
            _config.Namespaces.ToList().ForEach(ns => _namespaceImports.Add(ns));

            // the GeneratedClassContext defines the methods that are generated to handle the template
            // control like writing the generated output and also handle other control operations like
            // defining sections inside the template
            _generatedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral", "WriteTo", "WriteLiteralTo", typeof(HelperResult).FullName, "DefineSection")
            {
                ResolveUrlMethodName = "ResolveUrl",
            };
        }
コード例 #22
0
        /// <summary>
        /// Initializes a new instance of the Razor engine.
        /// </summary>
        /// <param name="defaultNamespace"></param>
        /// <param name="defaultClassName"></param>
        /// <param name="defaultBaseClass"></param>
        /// <param name="importedNamespaces"></param>
        /// <param name="innerTemplateType"></param>
        /// <param name="host"></param>
        /// <returns></returns>
        static RazorTemplateEngine CreateTemplateEngine(
            string defaultNamespace,
            string defaultClassName,
            Type defaultBaseClass,
            IEnumerable <string> importedNamespaces,
            Type innerTemplateType,
            RazorEngineHost host)
        {
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            // required portions of template implementation
            var ctx = new GeneratedClassContext(
                "Execute",
                writeMethod,
                writeLiteralMethod,
                writeToMethod,
                writeLiteralToMethod,
                innerTemplateType != null ? innerTemplateType.FullName : typeof(HelperResult).FullName,
                defineSectionMethod,
                beginContextMethod,
                endContextMethod);

            ctx.WriteAttributeMethodName   = writeAttributeMethod;
            ctx.WriteAttributeToMethodName = writeAttributeToMethod;
            ctx.LayoutPropertyName         = layoutProperty;

            // configure host
            host.GeneratedClassContext = ctx;
            if (importedNamespaces != null)
            {
                host.NamespaceImports.UnionWith(importedNamespaces);
            }
            return(new RazorTemplateEngine(host));
        }
コード例 #23
0
ファイル: MvcRazorHost.cs プロジェクト: lodejard/AllNetCore
        internal MvcRazorHost(IChunkTreeCache chunkTreeCache, RazorPathNormalizer pathNormalizer)
            : base(new CSharpRazorCodeLanguage())
        {
            _pathNormalizer = pathNormalizer;
            _chunkTreeCache = chunkTreeCache;

            DefaultBaseClass = $"{BaseType}<{ChunkHelper.TModelToken}>";
            DefaultNamespace = "Asp";
            // Enable instrumentation by default to allow precompiled views to work with BrowserLink.
            EnableInstrumentation = true;
            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "ExecuteAsync",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "Microsoft.AspNetCore.Mvc.Razor.HelperResult",
                defineSectionMethodName: "DefineSection",
                generatedTagHelperContext: new GeneratedTagHelperContext
            {
                ExecutionContextTypeName      = typeof(TagHelperExecutionContext).FullName,
                ExecutionContextAddMethodName = nameof(TagHelperExecutionContext.Add),
                ExecutionContextAddTagHelperAttributeMethodName =
                    nameof(TagHelperExecutionContext.AddTagHelperAttribute),
                ExecutionContextAddHtmlAttributeMethodName          = nameof(TagHelperExecutionContext.AddHtmlAttribute),
                ExecutionContextAddMinimizedHtmlAttributeMethodName =
                    nameof(TagHelperExecutionContext.AddMinimizedHtmlAttribute),
                ExecutionContextOutputPropertyName = nameof(TagHelperExecutionContext.Output),

                RunnerTypeName           = typeof(TagHelperRunner).FullName,
                RunnerRunAsyncMethodName = nameof(TagHelperRunner.RunAsync),

                ScopeManagerTypeName        = typeof(TagHelperScopeManager).FullName,
                ScopeManagerBeginMethodName = nameof(TagHelperScopeManager.Begin),
                ScopeManagerEndMethodName   = nameof(TagHelperScopeManager.End),

                TagHelperContentTypeName = typeof(TagHelperContent).FullName,

                // Can't use nameof because RazorPage is not accessible here.
                CreateTagHelperMethodName = "CreateTagHelper",
                FormatInvalidIndexerAssignmentMethodName = "InvalidTagHelperIndexerAssignment",
                StartTagHelperWritingScopeMethodName     = "StartTagHelperWritingScope",
                EndTagHelperWritingScopeMethodName       = "EndTagHelperWritingScope",

                // Can't use nameof because IHtmlHelper is (also) not accessible here.
                MarkAsHtmlEncodedMethodName           = HtmlHelperPropertyName + ".Raw",
                BeginAddHtmlAttributeValuesMethodName = "BeginAddHtmlAttributeValues",
                EndAddHtmlAttributeValuesMethodName   = "EndAddHtmlAttributeValues",
                AddHtmlAttributeValueMethodName       = "AddHtmlAttributeValue",
                HtmlEncoderPropertyName = "HtmlEncoder",
                TagHelperContentGetContentMethodName            = nameof(TagHelperContent.GetContent),
                TagHelperOutputIsContentModifiedPropertyName    = nameof(TagHelperOutput.IsContentModified),
                TagHelperOutputContentPropertyName              = nameof(TagHelperOutput.Content),
                ExecutionContextSetOutputContentAsyncMethodName = nameof(TagHelperExecutionContext.SetOutputContentAsync),
            })
            {
                BeginContextMethodName = "BeginContext",
                EndContextMethodName   = "EndContext"
            };

            foreach (var ns in _defaultNamespaces)
            {
                NamespaceImports.Add(ns);
            }
        }
コード例 #24
0
        /// <summary>
        /// Initialies LightRazorHost with a specified fileprovider
        /// </summary>
        public RazorLightHost(IFileProvider viewsFileProvider) : base(new CSharpRazorCodeLanguage())
        {
            this._viewsFileProvider = viewsFileProvider;

            DefaultClassName      = _defaultClassName;
            DefaultNamespace      = _defaultNamespace;
            DefaultBaseClass      = $"{BaseType}<{ChunkHelper.TModelToken}>";
            EnableInstrumentation = false;             //This should not be true, unsell you want your code to work :)
            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "ExecuteAsync",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "Microsoft.AspNetCore.Mvc.Razor.HelperResult",
                defineSectionMethodName: "DefineSection",
                generatedTagHelperContext: new GeneratedTagHelperContext
            {
                ExecutionContextTypeName      = typeof(TagHelperExecutionContext).FullName,
                ExecutionContextAddMethodName = nameof(TagHelperExecutionContext.Add),
                ExecutionContextAddTagHelperAttributeMethodName =
                    nameof(TagHelperExecutionContext.AddTagHelperAttribute),
                ExecutionContextAddHtmlAttributeMethodName = nameof(TagHelperExecutionContext.AddHtmlAttribute),
                ExecutionContextOutputPropertyName         = nameof(TagHelperExecutionContext.Output),

                RunnerTypeName           = typeof(TagHelperRunner).FullName,
                RunnerRunAsyncMethodName = nameof(TagHelperRunner.RunAsync),

                ScopeManagerTypeName        = typeof(TagHelperScopeManager).FullName,
                ScopeManagerBeginMethodName = nameof(TagHelperScopeManager.Begin),
                ScopeManagerEndMethodName   = nameof(TagHelperScopeManager.End),

                TagHelperContentTypeName = typeof(TagHelperContent).FullName,

                // Can't use nameof because RazorPage is not accessible here.
                CreateTagHelperMethodName = "CreateTagHelper",
                FormatInvalidIndexerAssignmentMethodName = "InvalidTagHelperIndexerAssignment",
                StartTagHelperWritingScopeMethodName     = "StartTagHelperWritingScope",
                EndTagHelperWritingScopeMethodName       = "EndTagHelperWritingScope",
                BeginWriteTagHelperAttributeMethodName   = "BeginWriteTagHelperAttribute",
                EndWriteTagHelperAttributeMethodName     = "EndWriteTagHelperAttribute",

                // Can't use nameof because IHtmlHelper is (also) not accessible here.
                MarkAsHtmlEncodedMethodName           = HtmlHelperPropertyName + ".Raw",
                BeginAddHtmlAttributeValuesMethodName = "BeginAddHtmlAttributeValues",
                EndAddHtmlAttributeValuesMethodName   = "EndAddHtmlAttributeValues",
                AddHtmlAttributeValueMethodName       = "AddHtmlAttributeValue",
                HtmlEncoderPropertyName = "HtmlEncoder",
                TagHelperContentGetContentMethodName            = nameof(TagHelperContent.GetContent),
                TagHelperOutputIsContentModifiedPropertyName    = nameof(TagHelperOutput.IsContentModified),
                TagHelperOutputContentPropertyName              = nameof(TagHelperOutput.Content),
                ExecutionContextSetOutputContentAsyncMethodName = nameof(TagHelperExecutionContext.SetOutputContentAsync),
                TagHelperAttributeValuePropertyName             = nameof(TagHelperAttribute.Value),
            })
            {
                BeginContextMethodName = "BeginContext",
                EndContextMethodName   = "EndContext"
            };

            foreach (var ns in _defaultNamespaces)
            {
                NamespaceImports.Add(ns);
            }
        }