This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
RazorPageAdapter.cs
89 lines (74 loc) · 2.65 KB
/
RazorPageAdapter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
{
// Implements IRazorPage so that RazorPageBase-derived classes don't get activated twice.
//
// The page gets activated before handler methods run, but the RazorView will also activate
// each page.
public class RazorPageAdapter : IRazorPage, IModelTypeProvider
{
private readonly RazorPageBase _page;
private readonly Type _modelType;
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
public RazorPageAdapter(RazorPageBase page)
{
if (page == null)
{
throw new ArgumentNullException(nameof(page));
}
_page = page;
}
public RazorPageAdapter(RazorPageBase page, Type modelType)
{
_page = page ?? throw new ArgumentNullException(nameof(page));
_modelType = modelType ?? throw new ArgumentNullException(nameof(modelType));
}
public ViewContext ViewContext
{
get { return _page.ViewContext; }
set { _page.ViewContext = value; }
}
public IHtmlContent BodyContent
{
get { return _page.BodyContent; }
set { _page.BodyContent = value; }
}
public bool IsLayoutBeingRendered
{
get { return _page.IsLayoutBeingRendered; }
set { _page.IsLayoutBeingRendered = value; }
}
public string Path
{
get { return _page.Path; }
set { _page.Path = value; }
}
public string Layout
{
get { return _page.Layout; }
set { _page.Layout = value; }
}
public IDictionary<string, RenderAsyncDelegate> PreviousSectionWriters
{
get { return _page.PreviousSectionWriters; }
set { _page.PreviousSectionWriters = value; }
}
public IDictionary<string, RenderAsyncDelegate> SectionWriters => _page.SectionWriters;
public void EnsureRenderedBodyOrSections()
{
_page.EnsureRenderedBodyOrSections();
}
public Task ExecuteAsync()
{
return _page.ExecuteAsync();
}
Type IModelTypeProvider.GetModelType() => _modelType;
}
}