本文整理汇总了C#中IRequest.GetView方法的典型用法代码示例。如果您正苦于以下问题:C# IRequest.GetView方法的具体用法?C# IRequest.GetView怎么用?C# IRequest.GetView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRequest
的用法示例。
在下文中一共展示了IRequest.GetView方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NormalizePath
static char[] InvalidFileChars = new[] { '<', '>', '`' }; //Anonymous or Generic type names
private string NormalizePath(IRequest request, object dto)
{
if (dto != null && !(dto is DynamicRequestObject)) // this is for a view inside /views
{
//if we have a view name, use it.
var viewName = request.GetView();
if (string.IsNullOrWhiteSpace(viewName))
{
//use the response DTO name
viewName = dto.GetType().Name;
}
if (string.IsNullOrWhiteSpace(viewName))
{
//the request use the request DTO name.
viewName = request.OperationName;
}
var isInvalidName = viewName.IndexOfAny(InvalidFileChars) >= 0;
if (!isInvalidName)
{
return CombinePaths("views", Path.ChangeExtension(viewName, Config.RazorFileExtension));
}
}
// path/to/dir/default.cshtml
var path = request.PathInfo;
var defaultIndex = CombinePaths(path, Config.DefaultPageName);
if (Pages.ContainsKey(defaultIndex))
return defaultIndex;
return Path.ChangeExtension(path, Config.RazorFileExtension);
}
示例2: GetViewPageByResponse
public MarkdownPage GetViewPageByResponse(object dto, IRequest httpReq)
{
var httpResult = dto as IHttpResult;
if (httpResult != null)
{
dto = httpResult.Response;
}
//If View was specified don't look for anything else.
var viewName = httpReq.GetView();
if (viewName != null)
return GetViewPage(viewName);
if (dto != null)
{
var responseTypeName = dto.GetType().GetOperationName();
var markdownPage = GetViewPage(responseTypeName);
if (markdownPage != null) return markdownPage;
}
return httpReq != null ? GetViewPage(httpReq.OperationName) : null;
}