forked from joao-neves95/CSharpToTypescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvertorEngine.cs
96 lines (85 loc) · 3.26 KB
/
ConvertorEngine.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
90
91
92
93
94
95
96
using CSharpToTypescript.VSIX;
namespace CSharpToTypescript
{
public class ConvertorEngine
{
private CSharpToTypescriptConverter converter;
private ISettingStore currentSetingStore;
private CSharpToTypescriptConverter Converter
{
get
{
if (converter == null)
converter = new CSharpToTypescriptConverter();
return converter;
}
}
private ISettingStore CurrentSetingStore
{
get
{
if (currentSetingStore == null)
currentSetingStore = new MySettings();
return currentSetingStore;
}
}
/// <summary>
/// Remove strings like : internal, overwrite
/// </summary>
/// <param name="fileContent"></param>
/// <returns></returns>
private string RemoveParticularStrings(string fileContent)
{
string[] removables = { "internal", "overwrite" };
for (int i = 0; i < removables.Length; i++)
{
fileContent = fileContent.Replace(removables[i], "");
}
return fileContent;
}
private string ReplaceTryCatch(string fileContent)
{
fileContent = fileContent.Replace("try", "string TRY;");
fileContent = fileContent.Replace("catch", "string CATCH;");
return fileContent;
}
public string Convert(string fileContent, string fileName = "")
{
if (string.IsNullOrWhiteSpace(fileContent))
return "// empty input file;";
fileContent = this.RemoveParticularStrings(fileContent);
//fileContent = this.ReplaceTryCatch(fileContent);
string resultTsFile = Converter.ConvertToTypescript(fileContent, CurrentSetingStore);
if (string.IsNullOrWhiteSpace(resultTsFile))
resultTsFile = string.Format("/* ERROR: The file {0} could not be converted.\r\n{1}\r\n*/", fileName + ".cs", Converter.ConvertException);
return resultTsFile;
}
}
class MySettings : ISettingStore
{
public bool AddIPrefixInterfaceDeclaration { get => false; set { } }
public bool IsConvertListToArray { get => true; set { } }
public bool IsConvertMemberToCamelCase { get => false; set { } }
public bool IsConvertToInterface { get => false; set { } }
public bool IsInterfaceOptionalProperties { get => false; set { } }
public TypeNameReplacementData[] ReplacedTypeNameArray
{
get
{
return new TypeNameReplacementData[] {
new TypeNameReplacementData
{
NewTypeName = "Date",
OldTypeName = "DateTimeOffset"
},
new TypeNameReplacementData
{
NewTypeName = "Date",
OldTypeName = "DateTime"
}
};
}
set { }
}
}
}