当前位置: 首页>>代码示例>>C#>>正文


C# ViewLocationResult.Contents方法代码示例

本文整理汇总了C#中ViewLocationResult.Contents方法的典型用法代码示例。如果您正苦于以下问题:C# ViewLocationResult.Contents方法的具体用法?C# ViewLocationResult.Contents怎么用?C# ViewLocationResult.Contents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ViewLocationResult的用法示例。


在下文中一共展示了ViewLocationResult.Contents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertMarkdown

        /// <summary>
        /// Converts the markdown.
        /// </summary>
        /// <returns>
        /// HTML converted from markdown
        /// </returns>
        /// <param name='viewLocationResult'>
        /// View location result.
        /// </param>
        public string ConvertMarkdown(ViewLocationResult viewLocationResult)
        {
            string content =
                viewLocationResult.Contents().ReadToEnd();

            if (content.StartsWith("<!DOCTYPE html>"))
            {
                return MarkdownViewengineRender.RenderMasterPage(content);
            }

            var parser = new Markdown();
            var html = parser.Transform(content);
            return ParagraphSubstitution.Replace(html, "$1");
        }
开发者ID:kppullin,项目名称:Nancy,代码行数:23,代码来源:MarkDownViewEngine.cs

示例2: RenderView

        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="viewLocationResult">A <see cref="ViewLocationResult"/> instance, containing information on how to get the view template.</param>
        /// <param name="model">The model to be passed into the view</param>
        /// <param name="renderContext"></param>
        /// <returns>A response</returns>
        public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            return new HtmlResponse
            {
                Contents = stream =>
                {
                    var templateName = viewLocationResult.Name;

                    var handlebars = threadLocalHandlebars.Value;
                    handlebars.RegisterTemplate(templateName, () =>
                    {
                        using (var textReader = viewLocationResult.Contents())
                        {
                            return textReader.ReadToEnd();
                        }

                    });
                    foreach (var partial in viewLocator.GetAllCurrentlyDiscoveredViews().Where(x => x.Name.StartsWith("_")))
                    {
                        var partialName = partial.Name.TrimStart('_');
                        handlebars.RegisterPartial(partialName, () =>
                        {
                            using (var textReader = partial.Contents())
                            {
                                return textReader.ReadToEnd();
                            }
                        });
                    }
                    using (var writer = new StreamWriter(stream))
                    {
                        dynamic output;
                        try
                        {
                            output = handlebars.Transform(templateName, model);
                        }
                        catch (Exception)
                        {
                            //TODO: remove this exception handling after a few versions
                            var templateContents = viewLocationResult.Contents().ReadToEnd();
                            if (templateContents.Contains("{{> _") || templateContents.Contains("{{>_"))
                            {
                                throw new Exception(string.Format("Template '{0}' contains and underscore prefixed partial name. This is no longer required. Search for the string '{{>_' or '{{> _' in your template and remove the '_'.", templateName));
                            }
                            throw;
                        }
                        writer.Write(output);
                    }
                }
            };
        }
开发者ID:JenTechSystems,项目名称:Chevron,代码行数:57,代码来源:ChevronViewEngine.cs


注:本文中的ViewLocationResult.Contents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。