-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCSharpTypesMapping.cs
More file actions
63 lines (51 loc) · 1.7 KB
/
CSharpTypesMapping.cs
File metadata and controls
63 lines (51 loc) · 1.7 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
using System;
using System.Collections.Generic;
using System.Text;
namespace ObjectInitializerGenerator
{
internal static class CSharpTypesMapping
{
private static readonly Dictionary<string, string> Mappings = new Dictionary<string, string>
{
{ "string", "\"\"" },
{ "String", "\"\"" },
{ "bool", "true" },
{ "bool?", "true" },
{ "Boolean", "true" },
{ "Boolean?", "true" },
{ "Guid", "Guid.NewGuid()"},
{ "Datetime", "DateTime.Now"},
{ "Datetime?", "DateTime.Now"},
{ "DateTime", "DateTime.Now"},
{ "DateTime?", "DateTime.Now"},
{ "DateTimeOffset", "DateTimeOffset.Now"},
{ "DateTimeOffset?", "DateTimeOffset.Now"},
{ "int", "1"},
{ "int?", "1"},
{ "uint", "1"},
{ "long", "1"},
{ "double", "1"},
{ "Double", "1"},
{ "float", "1"},
{ "decimal", "1"},
{ "byte", "1"},
{ "char", "\'c\'"},
};
static internal string Map(string type)
{
return Mappings[type];
}
static internal string MapArray(ObjectModel type)
{
return string.Format("new {0}[]{{{1}}}", type.GenericType, Mappings[type.GenericType]);
}
static internal string MapObject(ObjectModel type)
{
if (type.PropertyType.Contains("IEnumerable"))
{
return string.Format("new {0}()", type.PropertyType.Replace("IEnumerable", "List"));
}
return string.Format("new {0}()", type.PropertyType);
}
}
}