FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ICP.NET/src/ClientGenerator/ClientSourceCode.cs at main · edjCase/ICP.NET · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
edjCase
/
ICP.NET
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
55
Code
Issues
6
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ICP.NET
/
src
/
ClientGenerator
/
ClientSourceCode.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
105 lines (93 loc) · 3.71 KB
Breadcrumbs
ICP.NET
/
src
/
ClientGenerator
/
ClientSourceCode.cs
Copy path
File metadata and controls
105 lines (93 loc) · 3.71 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
using
EdjCase
.
ICP
.
Candid
.
Mapping
.
Mappers
;
using
EdjCase
.
ICP
.
Candid
.
Models
;
using
EdjCase
.
ICP
.
Candid
.
Models
.
Types
;
using
EdjCase
.
ICP
.
Candid
.
Models
.
Values
;
using
EdjCase
.
ICP
.
ClientGenerator
;
using
Microsoft
.
CodeAnalysis
;
using
Microsoft
.
CodeAnalysis
.
CSharp
;
using
Microsoft
.
CodeAnalysis
.
CSharp
.
Syntax
;
using
Microsoft
.
CodeAnalysis
.
Editing
;
using
Microsoft
.
CodeAnalysis
.
Formatting
;
using
Microsoft
.
CodeAnalysis
.
Options
;
using
Microsoft
.
VisualBasic
;
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
IO
;
using
System
.
Linq
;
namespace
EdjCase
.
ICP
.
ClientGenerator
{
/// <summary>
/// A model containing the client code to be rendered
/// </summary>
public
class
ClientSyntax
{
/// <summary>
/// The name of the client
/// </summary>
public
string
Name
{
get
;
}
/// <summary>
/// The syntax of the client file
/// </summary>
public
CompilationUnitSyntax
ClientFile
{
get
;
}
/// <summary>
/// The syntax of different declared types for the client
/// </summary>
public
List
<
(
string
Name
,
CompilationUnitSyntax
Syntax
)
>
TypeFiles
{
get
;
}
/// <param name="name">The name of the client</param>
/// <param name="clientFile">The syntax of the client file</param>
/// <param name="typeFiles">The syntax of different declared types for the client</param>
public
ClientSyntax
(
string
name
,
CompilationUnitSyntax
clientFile
,
List
<
(
string
Name
,
CompilationUnitSyntax
Syntax
)
>
typeFiles
)
{
this
.
Name
=
name
??
throw
new
ArgumentNullException
(
nameof
(
name
)
)
;
this
.
ClientFile
=
clientFile
??
throw
new
ArgumentNullException
(
nameof
(
clientFile
)
)
;
this
.
TypeFiles
=
typeFiles
??
throw
new
ArgumentNullException
(
nameof
(
typeFiles
)
)
;
}
/// <summary>
/// Rewrites the syntax with the specified `CSharpSyntaxRewriter`
/// </summary>
/// <param name="rewriter">A `CSharpSyntaxRewriter` to rewrite the csharp syntax</param>
/// <returns>Updated client syntax</returns>
public
ClientSyntax
Rewrite
(
CSharpSyntaxRewriter
rewriter
)
{
CompilationUnitSyntax
updatedClientFile
=
(
CompilationUnitSyntax
)
rewriter
.
Visit
(
this
.
ClientFile
)
;
List
<
(
string
Name
,
CompilationUnitSyntax
updatedSyntax
)
>
updatedTypeFiles
=
this
.
TypeFiles
.
Select
(
(
typeFile
)
=>
{
CompilationUnitSyntax
updatedSyntax
=
(
CompilationUnitSyntax
)
rewriter
.
Visit
(
typeFile
.
Syntax
)
;
return
(
typeFile
.
Name
,
updatedSyntax
)
;
}
)
.
ToList
(
)
;
return
new
ClientSyntax
(
this
.
Name
,
updatedClientFile
,
updatedTypeFiles
)
;
}
/// <summary>
/// Converts the file syntax objects into source code string values to use as a file
/// </summary>
/// <returns>Client and type source code file contents</returns>
public
(
string
ClientFile
,
List
<
(
string
Name
,
string
Contents
)
>
TypeFiles
)
GenerateFileContents
(
)
{
string
clientFile
=
GenerateFileContents
(
this
.
ClientFile
)
;
List
<
(
string
Name
,
string
Contents
)
>
typeFileContents
=
this
.
TypeFiles
.
Select
(
(
typeFile
)
=>
{
string
contents
=
GenerateFileContents
(
typeFile
.
Syntax
)
;
return
(
typeFile
.
Name
,
contents
)
;
}
)
.
ToList
(
)
;
return
(
clientFile
,
typeFileContents
)
;
}
/// <summary>
/// Helper function to turn a client or type into a string of file contents
/// </summary>
/// <param name="syntax">The client or type file to convert to a string</param>
/// <returns>String source code of the specified syntax</returns>
public
static
string
GenerateFileContents
(
CompilationUnitSyntax
syntax
)
{
// Setup formatting options
AdhocWorkspace
workspace
=
new
(
)
;
OptionSet
options
=
workspace
.
Options
.
WithChangedOption
(
FormattingOptions
.
UseTabs
,
LanguageNames
.
CSharp
,
value
:
true
)
.
WithChangedOption
(
FormattingOptions
.
NewLine
,
LanguageNames
.
CSharp
,
value
:
Environment
.
NewLine
)
;
return
Formatter
.
Format
(
syntax
,
workspace
,
options
)
.
ToFullString
(
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL