forked from hpj1106/Transformer.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNet.cs
More file actions
118 lines (103 loc) · 3.74 KB
/
Net.cs
File metadata and controls
118 lines (103 loc) · 3.74 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* @version: 2.1.1
* @author: Ext.NET, Inc. http://www.ext.net/
* @date: 2012-12-16
* @copyright: Copyright (c) 2007-2012, Ext.NET, Inc. (http://www.ext.net/). All rights reserved.
* @license: See license.txt and http://www.ext.net/licensetransformer/.
* @website: http://www.ext.net/
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace Transformer.NET
{
public static class Net
{
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string Transform(string text)
{
return Transformer.NET.TextTransformer.Transform(text);
}
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <param name="config"></param>
/// <returns></returns>
public static string Transform(string text, TextTransformerConfig config)
{
return Transformer.NET.TextTransformer.Transform(text, config);
}
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string Transform(string text, Dictionary<string, string> variables)
{
return Transformer.NET.TextTransformer.Transform(text, variables);
}
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string Transform(string text, List<Type> tokensType)
{
return Transformer.NET.TextTransformer.Transform(text, tokensType);
}
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string Transform(string text, List<Type> tokensType, Dictionary<string, string> variables)
{
return Transformer.NET.TextTransformer.Transform(text, tokensType, variables);
}
/* Helpers */
private static string GetTokenName(Type tokenType)
{
object[] attrs = tokenType.GetCustomAttributes(typeof(TagNameAttribute), true);
return ((TagNameAttribute)attrs[0]).Name;
}
public static string CreateToken(Type tokenType, Dictionary<string, string> attributes)
{
return Transformer.NET.Net.CreateToken(Transformer.NET.Net.GetTokenName(tokenType), attributes);
}
public static string CreateToken(Type tokenType, Dictionary<string, string> attributes, string value)
{
return Transformer.NET.Net.CreateToken(Transformer.NET.Net.GetTokenName(tokenType), attributes, value);
}
public static string CreateToken(string token, Dictionary<string, string> attributes)
{
return Transformer.NET.Net.CreateToken(token, attributes, null);
}
public static string CreateToken(string token, Dictionary<string,string> attributes, string value)
{
StringBuilder sb = new StringBuilder();
sb.Append("<#:");
sb.Append(token);
if (attributes != null && attributes.Count > 0)
{
foreach (string key in attributes.Keys)
{
sb.AppendFormat(" {0}=\"{1}\"", key, attributes[key]);
}
}
if (value != null && value.Length > 0)
{
sb.AppendFormat(">{0}</#:{1}>", value, token);
}
else
{
sb.Append(" />");
}
return sb.ToString();
}
}
}