-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.cs
49 lines (41 loc) · 1.48 KB
/
View.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
using System.IO;
using System.Web;
using System.Text.RegularExpressions;
namespace Maussoft.Mvc
{
public class View<TSession> where TSession : new()
{
protected WebContext<TSession> Context = null;
private StringWriter writer = new StringWriter();
public virtual void Header() { }
public virtual void Content() { }
public virtual void Footer() { }
public string Render(WebContext<TSession> context)
{
Context = context;
this.writer = new StringWriter();
Header(); Content(); Footer();
return this.writer.ToString();
}
private static string replace(string input, object[] arguments)
{
if (arguments.Length == 0) return input;
return Regex.Replace(input, @"{([0-9]+)}", delegate (Match match)
{
int index;
if (!int.TryParse(match.Groups[1].Value, out index)) return match.Value;
if (index >= arguments.Length) return match.Value;
return HttpUtility.HtmlEncode(arguments[index] as string);
}
);
}
public void Write(string format, params object[] arguments)
{
this.writer.Write(replace(format, arguments));
}
public void WriteLine(string format = "", params object[] arguments)
{
this.writer.WriteLine(replace(format, arguments));
}
}
}