├── .gitattributes
├── .github
└── workflows
│ ├── dotnetcore.yml
│ └── nuget publish.yml
├── .gitignore
├── Directory.Build.props
├── README.md
├── SourceFusion.sln
├── build
└── Version.props
├── docs
├── README.md
└── how-to-contribute.md
├── sample
├── .gitattributes
├── .gitignore
├── dotnetCampus.Core
│ ├── IInteresting.cs
│ ├── InterestingAttribute.cs
│ └── dotnetCampus.Core.csproj
├── dotnetCampus.Extension
│ ├── CompilingServices
│ │ └── ExtensionExport.cs
│ ├── Extensions
│ │ └── .gitignore
│ ├── Foo.cs
│ └── dotnetCampus.Extension.csproj
├── dotnetCampus.SourceGenerator
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ └── dotnetCampus.SourceGenerator.csproj
├── dotnetCampus.SourcePerformance.sln
└── dotnetCampus.SourcePerformance
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Framework
│ ├── ExtensionManager.cs
│ ├── PerformanceCounter.cs
│ └── Services.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── Program.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── dotnetCampus.SourcePerformance.csproj
├── src
├── SourceFusion.Tool
│ ├── App.cs
│ ├── Assets
│ │ ├── build
│ │ │ └── Package.targets
│ │ └── buildMultiTargeting
│ │ │ └── Package.targets
│ ├── Cli
│ │ └── Options.cs
│ ├── CompileTime
│ │ ├── CompileAssembly.cs
│ │ ├── CompileAttribute.cs
│ │ ├── CompileField.cs
│ │ ├── CompileFile.cs
│ │ ├── CompileMember.cs
│ │ ├── CompileMethod.cs
│ │ ├── CompileProperty.cs
│ │ └── CompileType.cs
│ ├── Core
│ │ ├── CompilingContext.cs
│ │ ├── CompilingException.cs
│ │ └── ProjectCompilingContext.cs
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── SourceFusion.Core.csproj.DotSettings
│ ├── SourceFusion.Tool.csproj
│ ├── SourceFusion.Tool.csproj.DotSettings
│ ├── Syntax
│ │ ├── CompileTypeVisitor.cs
│ │ ├── PlaceholderVisitor.cs
│ │ └── SyntaxTreeCompilingExtensions.cs
│ ├── Templates
│ │ ├── ArrayPlaceholder.cs
│ │ ├── AttributedTypesPlaceholder.cs
│ │ ├── PlaceholderInfo.cs
│ │ └── TemplateTransformer.cs
│ ├── Transforming
│ │ └── CodeTransformer.cs
│ └── Utils
│ │ ├── ILogger.cs
│ │ ├── Logger.cs
│ │ └── PathEx.cs
└── SourceFusion
│ ├── Attributes_
│ ├── CompileTimeCodeAttribute.cs
│ ├── CompileTimeMethodAttribute.cs
│ └── CompileTimeTemplateAttribute.cs
│ ├── CompileCodeSnippet.cs
│ ├── CompileTime
│ ├── ICompileAssembly.cs
│ ├── ICompileAttribute.cs
│ ├── ICompileAttributeProvider.cs
│ ├── ICompileField.cs
│ ├── ICompileInterface.cs
│ ├── ICompileMember.cs
│ ├── ICompileMethod.cs
│ ├── ICompileProperty.cs
│ └── ICompileType.cs
│ ├── FileType.cs
│ ├── ICodeTransformer.cs
│ ├── ICompilingContext.cs
│ ├── Metadata_
│ ├── AttributedTypeMetadata.cs
│ └── AttributedTypeMetadataCollection.cs
│ ├── Placeholder.cs
│ ├── SourceFusion.Core.csproj
│ ├── SourceFusion.Core.csproj.DotSettings
│ ├── TransformingContext.cs
│ └── Utils_
│ └── CompileCodeSnippetBuilder.cs
└── tests
└── SourceFusion.Tests
├── CompileTimeTests.cs
├── Debug_
├── GenerateGeneric.cs
└── ModuleCollector.cs
├── Fakes
├── ActionCommand.cs
├── DI
│ ├── ExportAttribute.cs
│ ├── Foo.cs
│ ├── IFoo.cs
│ └── ImportAttribute.cs
├── Modules
│ ├── BarModule.cs
│ ├── FooModule.cs
│ ├── IModule.cs
│ ├── ModuleAttribute.cs
│ └── ModuleInfo.cs
└── Mvvm
│ ├── FooViewModel.cs
│ ├── IFooViewModel.cs
│ └── ViewModelBase.cs
├── SourceFusion.Tests.csproj
└── SourceFusion.Tests.csproj.DotSettings
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.github/workflows/dotnetcore.yml:
--------------------------------------------------------------------------------
1 | name: .NET Core
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 |
8 | runs-on: windows-latest
9 |
10 |
11 | steps:
12 | - uses: actions/checkout@v1
13 | - name: Setup .NET Core
14 | uses: actions/setup-dotnet@v1
15 | with:
16 | dotnet-version: '8.0.x'
17 | - name: Build with dotnet
18 | run: dotnet build --configuration Release -v n
19 |
--------------------------------------------------------------------------------
/.github/workflows/nuget publish.yml:
--------------------------------------------------------------------------------
1 | name: NuGet Publish
2 |
3 | on:
4 | push:
5 | tags:
6 | - '*'
7 |
8 | jobs:
9 | build:
10 | runs-on: windows-latest
11 |
12 | steps:
13 | - uses: actions/checkout@v1
14 | - name: Setup .NET Core
15 | uses: actions/setup-dotnet@v1
16 | with:
17 | dotnet-version: '8.0.x'
18 |
19 | - name: Install dotnet tool
20 | run: dotnet tool install -g dotnetCampus.TagToVersion
21 |
22 | - name: Set tag to version
23 | run: dotnet TagToVersion -t ${{ github.ref }}
24 |
25 | - name: Build with dotnet
26 | run: dotnet build --configuration Release -v n
27 | shell: pwsh
28 |
29 | - name: Pack with dotnet
30 | run: dotnet pack --configuration Release --no-build
31 |
32 | - name: Install Nuget
33 | uses: nuget/setup-nuget@v1
34 | with:
35 | nuget-version: '5.x'
36 |
37 | - name: Add private GitHub registry to NuGet
38 | run: |
39 | nuget sources add -name github -Source https://nuget.pkg.github.com/ORGANIZATION_NAME/index.json -Username ORGANIZATION_NAME -Password ${{ secrets.GITHUB_TOKEN }}
40 |
41 | - name: Push generated package to GitHub registry
42 | run: |
43 | nuget push .\bin\release\*.nupkg -Source github -SkipDuplicate
44 | nuget push .\bin\release\*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NugetKey }} -NoSymbols
45 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
262 | /src/SourceFusion.Tool/Properties/launchSettings.json
263 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildThisFileDirectory)bin\$(Configuration)
5 | dotnet-campus
6 | dotnet-campus
7 | latest
8 | true
9 | false
10 | MIT
11 | Copyright (c) 2018-2023 dotnet-campus
12 | https://github.com/dotnet-campus/SourceFusion
13 | https://github.com/dotnet-campus/SourceFusion.git
14 | git
15 | source;dotnet;nuget;msbuild;compile
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SourceFusion
2 |
3 | SourceFusion 是一套预编译框架。
4 |
5 | 当项目安装 SourceFusion 了之后,项目中即可开始书写预编译代码。通过执行这些预编译代码,项目可以在编译期间执行一些平时需要在运行时执行的代码。这种方式能够将耗时的运行时代码迁移到编译期执行,大幅度提升运行时性能。
6 |
7 | |Build|NuGet|
8 | |--|--|
9 | ||[](https://www.nuget.org/packages/dotnetCampus.SourceFusion)|
10 |
11 | ** 由于 SourceFusion 编写过早导致技术过于陈旧且 API 设计不够现代化,更推荐你使用设计和兼容性更优的 [Telescope](https://github.com/dotnet-campus/Telescope) 代替 **
12 |
13 | ## 入门
14 |
15 | ### 安装 NuGet 包
16 |
17 | 在 NuGet 源上搜索 `SourceFusion` 寻找已发布的 NuGet 包。由于目前尚未发布正式版,所以你需要指定搜索“预编译版本”才能搜索到此包。
18 |
19 | 在需要编写预编译代码的项目中安装此 NuGet 包即可。
20 |
21 | ### 编写预编译代码
22 |
23 | 你有两种编写预编译代码的方法:
24 |
25 | 1. 纯文本代码转换;
26 | 1. 模板转换。
27 |
28 | 以下代码为纯文本预编译代码的 Hello World 实现。HelloWorldTransformer.cs 中的 `Transform` 方法将在编译期间执行,用于将 HelloWorld.cs 文件中的输出改为 `Hello World!`。
29 |
30 | ```csharp
31 | [CompileTimeCode("HelloWorld.cs")]
32 | public class HelloWorldTransformer : IPlainCodeTransformer
33 | {
34 | public string Transform(string originalText, TransformingContext context)
35 | {
36 | return originalText.Replace("Hello", "Hello World!");
37 | }
38 | }
39 | ```
40 |
41 | ```csharp
42 | using System;
43 |
44 | public class HelloWorld
45 | {
46 | public void SayHello()
47 | {
48 | Console.WriteLine("Hello");
49 | }
50 | }
51 | ```
52 |
53 | 以下代码为模板转换的 Hello World 实现:
54 |
55 | ```csharp
56 | using System;
57 |
58 | namespace SourceFusion.Tests
59 | {
60 | [CompileTimeTemplate]
61 | public class HelloWorld
62 | {
63 | public void SayHello()
64 | {
65 | var outputs = Placeholder.Array(context =>
66 | {
67 | // 这里使用两个引号来转义一个引号,最终我们得到了一个包含三个单词部分的数组。
68 | return @"""Hello "", ""World"", ""!""";
69 | });
70 | foreach (var output in outputs)
71 | {
72 | Console.Write(output);
73 | }
74 | }
75 | }
76 | }
77 | ```
78 |
79 | ## 为此项目开发
80 |
81 | 非常期望你能加入到 SourceFusion 的开发中来,请阅读 [如何为 SourceFusion 贡献代码](/docs/how-to-contribute.md) 了解开发相关的约定和技术要求。
82 |
--------------------------------------------------------------------------------
/SourceFusion.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.6.33723.286
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceFusion.Tool", "src\SourceFusion.Tool\SourceFusion.Tool.csproj", "{EFDCE47F-3FCE-4428-9F63-340806876FE5}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceFusion.Core", "src\SourceFusion\SourceFusion.Core.csproj", "{833511F2-E986-4D5E-8D34-EF53786801F3}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceFusion.Tests", "tests\SourceFusion.Tests\SourceFusion.Tests.csproj", "{5978AAB0-C4C1-44AF-AB92-27F8ECBF6F69}"
11 | EndProject
12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{02D03DE5-1A19-4002-92BD-0E3DC61A53C4}"
13 | EndProject
14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{41B6AF7A-C4D6-42F4-A1D2-A2E4271B2FD3}"
15 | ProjectSection(SolutionItems) = preProject
16 | .gitattributes = .gitattributes
17 | .gitignore = .gitignore
18 | build\config.xml = build\config.xml
19 | Directory.Build.props = Directory.Build.props
20 | build\Version.props = build\Version.props
21 | EndProjectSection
22 | EndProject
23 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHub Actions", "GitHub Actions", "{5A85E9ED-415C-4720-BF26-8CF8A97CB832}"
24 | ProjectSection(SolutionItems) = preProject
25 | .github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml
26 | .github\workflows\nuget publish.yml = .github\workflows\nuget publish.yml
27 | EndProjectSection
28 | EndProject
29 | Global
30 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
31 | Debug|Any CPU = Debug|Any CPU
32 | Release|Any CPU = Release|Any CPU
33 | EndGlobalSection
34 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
35 | {EFDCE47F-3FCE-4428-9F63-340806876FE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36 | {EFDCE47F-3FCE-4428-9F63-340806876FE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
37 | {EFDCE47F-3FCE-4428-9F63-340806876FE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
38 | {EFDCE47F-3FCE-4428-9F63-340806876FE5}.Release|Any CPU.Build.0 = Release|Any CPU
39 | {833511F2-E986-4D5E-8D34-EF53786801F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40 | {833511F2-E986-4D5E-8D34-EF53786801F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
41 | {833511F2-E986-4D5E-8D34-EF53786801F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
42 | {833511F2-E986-4D5E-8D34-EF53786801F3}.Release|Any CPU.Build.0 = Release|Any CPU
43 | {5978AAB0-C4C1-44AF-AB92-27F8ECBF6F69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
44 | {5978AAB0-C4C1-44AF-AB92-27F8ECBF6F69}.Debug|Any CPU.Build.0 = Debug|Any CPU
45 | {5978AAB0-C4C1-44AF-AB92-27F8ECBF6F69}.Release|Any CPU.ActiveCfg = Release|Any CPU
46 | {5978AAB0-C4C1-44AF-AB92-27F8ECBF6F69}.Release|Any CPU.Build.0 = Release|Any CPU
47 | EndGlobalSection
48 | GlobalSection(SolutionProperties) = preSolution
49 | HideSolutionNode = FALSE
50 | EndGlobalSection
51 | GlobalSection(NestedProjects) = preSolution
52 | {5978AAB0-C4C1-44AF-AB92-27F8ECBF6F69} = {02D03DE5-1A19-4002-92BD-0E3DC61A53C4}
53 | EndGlobalSection
54 | GlobalSection(ExtensibilityGlobals) = postSolution
55 | SolutionGuid = {22702A10-22E1-4670-8FCA-9581202E6CAB}
56 | EndGlobalSection
57 | EndGlobal
58 |
--------------------------------------------------------------------------------
/build/Version.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1.0.0-alpha
4 |
5 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | # SourceFusion
2 |
3 |
--------------------------------------------------------------------------------
/docs/how-to-contribute.md:
--------------------------------------------------------------------------------
1 | # 如何为 SourceFusion 贡献代码
2 |
3 | SourceFusion 基于 Roslyn 对代码进行编译期分析和执行。
4 |
5 | ## 核心程序集
6 |
7 | 核心程序集有两个:
8 |
9 | - SourceFusion.Core
10 | - SourceFusion.Tool
11 |
12 | SourceFusion.Core 是抽象部分,当作为 NuGet 包安装后,会被目标程序集引用,这样目标程序集可以编写出编译期间运行的的代码。SourceFusion.Tool 是对以上抽象的具体实现部分,当作为 NuGet 包安装后,如果目标程序集执行编译操作,那么此程序集将被执行。也就是说,SourceFusion.Core 的存在是为了让目标程序集能够编写出编译期间执行的代码,而 SourceFusion.Tool 则是执行目标程序集中指定为编译期执行的代码。
13 |
14 | 这两个程序集有一些开发上的约定。
15 |
16 | - SourceFusion.Core 由于会被目标项目通过 PackageReference 的方式引用,所以不要额外引入第三方依赖。
17 | - SourceFusion.Tool 由于其控制台输出被用于特殊用途,所以请不要使用 `Console.WriteLine` 等进行调试。
18 |
--------------------------------------------------------------------------------
/sample/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/sample/dotnetCampus.Core/IInteresting.cs:
--------------------------------------------------------------------------------
1 | namespace dotnetCampus
2 | {
3 | public interface IInteresting
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/sample/dotnetCampus.Core/InterestingAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace dotnetCampus
4 | {
5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
6 | public sealed class InterestingAttribute : Attribute
7 | {
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/sample/dotnetCampus.Core/dotnetCampus.Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | dotnetCampus
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/sample/dotnetCampus.Extension/CompilingServices/ExtensionExport.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using dotnetCampus.SourceFusion;
4 |
5 | namespace dotnetCampus.CompilingServices
6 | {
7 | [CompileTimeTemplate]
8 | public class ExtensionExport
9 | {
10 | public IReadOnlyList Interestings = Placeholder.Array(context =>
11 | {
12 | return new CompileCodeSnippet(@"new {0}(),
13 | ", context.Assembly.GetTypes()
14 | .Where(type => type.Attributes.Any(x => x.Match("Interesting")))
15 | .Select(x => x.FullName));
16 | });
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/sample/dotnetCampus.Extension/Extensions/.gitignore:
--------------------------------------------------------------------------------
1 | *.cs
2 |
--------------------------------------------------------------------------------
/sample/dotnetCampus.Extension/Foo.cs:
--------------------------------------------------------------------------------
1 | namespace dotnetCampus
2 | {
3 | public class Foo
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/sample/dotnetCampus.Extension/dotnetCampus.Extension.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | dotnetCampus
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample/dotnetCampus.SourceGenerator/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 |
6 | namespace dotnetCampus.SourceGenerator
7 | {
8 | class Program
9 | {
10 | static void Main(string[] args)
11 | {
12 | foreach (var arg in args)
13 | {
14 | var path = Path.GetFullPath(arg);
15 | Generate(path, classCount: 20000, attributedCount: 100);
16 | }
17 | }
18 |
19 | private static void Generate(string folderPath, int classCount, int attributedCount)
20 | {
21 | var folder = new DirectoryInfo(folderPath);
22 |
23 | var generator = new WordGenerator();
24 |
25 | for (var i = 0; i < classCount; i++)
26 | {
27 | var @namespace = generator.Generate();
28 | var @class = generator.Generate();
29 | var attribute = attributedCount-- > 0 ? @"
30 | [Interesting]" : "";
31 |
32 | var code = $@"
33 | using System;
34 | using System.Collections.Generic;
35 | using System.Text;
36 | using dotnetCampus;
37 |
38 | namespace {@namespace}
39 | {{{attribute}
40 | public class {@class} : IInteresting
41 | {{
42 | public string Foo {{ get; set; }}
43 | }}
44 | }}";
45 |
46 | var directory = Path.Combine(folder.FullName, (i % 100).ToString().PadLeft(2, '0'));
47 | if (!Directory.Exists(directory))
48 | {
49 | Directory.CreateDirectory(directory);
50 | }
51 |
52 | File.WriteAllText(Path.Combine(directory, @class + ".cs"), code);
53 | }
54 | }
55 |
56 | private static void LownearkeajooSasouStegisti(string folderPath)
57 | {
58 | var folder = new DirectoryInfo(folderPath);
59 | if (!folder.Exists)
60 | {
61 | folder.Create();
62 | }
63 |
64 | var fawniSorhaHereni = new List();
65 | var deleeTacarirouWulall = new WordGenerator();
66 |
67 | for (int gupoudigorKihirkercou = 0; gupoudigorKihirkercou < 1000; gupoudigorKihirkercou++)
68 | {
69 | var teaJawtu = deleeTacarirouWulall.Generate();
70 |
71 | for (int mirxarJeredrairsear = 0; mirxarJeredrairsear < 5; mirxarJeredrairsear++)
72 | {
73 | var cicirRarsonisallJearwelxe = deleeTacarirouWulall.Generate();
74 |
75 | var facoSaijeesereniXaimow = $@"
76 | using System;
77 | using System.Collections.Generic;
78 | using System.Text;
79 |
80 | namespace {teaJawtu}
81 | {{
82 | public class {cicirRarsonisallJearwelxe}
83 | {{
84 | public string Foo {{ get; set; }}
85 | }}
86 | }}";
87 | if (mirxarJeredrairsear == 0)
88 | {
89 | fawniSorhaHereni.Add(teaJawtu + "." + cicirRarsonisallJearwelxe);
90 | }
91 |
92 | File.WriteAllText(
93 | Path.Combine(folder.FullName, cicirRarsonisallJearwelxe + ".cs"),
94 | facoSaijeesereniXaimow);
95 | }
96 | }
97 |
98 | var jawjearPalfokallPuwuTearbourer = new StringBuilder();
99 |
100 | jawjearPalfokallPuwuTearbourer.Append(@"
101 |
102 |
103 | Exe
104 | netcoreapp2.1
105 |
106 |
107 |
108 | ");
109 |
110 |
111 | jawjearPalfokallPuwuTearbourer.Append(@"
112 |
113 | ");
114 |
115 | File.WriteAllText(Path.Combine(folder.FullName, "TirkalltremceFalgawCouwabupu.csproj"),
116 | jawjearPalfokallPuwuTearbourer.ToString());
117 |
118 | jawjearPalfokallPuwuTearbourer.Clear();
119 |
120 | var cepepiSowneKorrer = @"using System;
121 | using System.Diagnostics;
122 |
123 | namespace CouwharjeMerball
124 | {
125 | class Program
126 | {
127 | static void Main(string[] args)
128 | {
129 | var dafuWhayroubaXouma = new Stopwatch();
130 | dafuWhayroubaXouma.Start();
131 | var kawgeDeesearsofas = new KawgeDeesearsofas();
132 | kawgeDeesearsofas.LurtrajaboPearbubirXinene();
133 | dafuWhayroubaXouma.Stop();
134 | Console.WriteLine(dafuWhayroubaXouma.ElapsedMilliseconds);
135 | }
136 | }
137 | }
138 | ";
139 | File.WriteAllText(Path.Combine(folder.FullName, "Program.cs"), cepepiSowneKorrer);
140 |
141 | jawjearPalfokallPuwuTearbourer.Append(@"namespace CouwharjeMerball
142 | {
143 | class KawgeDeesearsofas
144 | {
145 | public void LurtrajaboPearbubirXinene()
146 | {
147 | ");
148 |
149 |
150 | foreach (var ferosarTadir in fawniSorhaHereni)
151 | {
152 | jawjearPalfokallPuwuTearbourer.Append(" new " + ferosarTadir + "();");
153 | jawjearPalfokallPuwuTearbourer.Append("\r\n");
154 | }
155 |
156 | jawjearPalfokallPuwuTearbourer.Append(@" }
157 | }
158 | }");
159 |
160 | File.WriteAllText(Path.Combine(folder.FullName, "KawgeDeesearsofas.cs"),
161 | jawjearPalfokallPuwuTearbourer.ToString());
162 | }
163 |
164 | private static void KijeSabacher()
165 | {
166 | var jisqeCorenerairTurpalhee = new DirectoryInfo("StuLartearou");
167 |
168 | jisqeCorenerairTurpalhee.Create();
169 |
170 | var jairtallworBeakoo = new WordGenerator();
171 |
172 | List geeberecereHouroudo = new List();
173 |
174 | List xawsosapawTabejetai = new List();
175 |
176 | for (int qeltasmisVigallSearniste = 0; qeltasmisVigallSearniste < 1000; qeltasmisVigallSearniste++)
177 | {
178 | string louwebirPemtrasrereYorta = "";
179 |
180 | var fismeerurniDawwall = jairtallworBeakoo.Generate();
181 |
182 | var nemirchouDamounu = jisqeCorenerairTurpalhee.CreateSubdirectory(fismeerurniDawwall);
183 |
184 | var beltuzoKoma = @"
185 |
186 |
187 | netcoreapp2.1
188 |
189 |
190 |
191 | ";
192 | xawsosapawTabejetai.Add(fismeerurniDawwall);
193 |
194 | File.WriteAllText(Path.Combine(nemirchouDamounu.FullName, fismeerurniDawwall + ".csproj"), beltuzoKoma);
195 |
196 | for (int roupairDufallne = 0; roupairDufallne < 5; roupairDufallne++)
197 | {
198 | var whowjallKelpirhorWirweSemjaneldroo = jairtallworBeakoo.Generate();
199 |
200 | if (roupairDufallne == 0)
201 | {
202 | louwebirPemtrasrereYorta = fismeerurniDawwall + "." + whowjallKelpirhorWirweSemjaneldroo;
203 | }
204 |
205 | var facoSaijeesereniXaimow = $@"
206 | using System;
207 | using System.Collections.Generic;
208 | using System.Text;
209 |
210 | namespace {fismeerurniDawwall}
211 | {{
212 | public class {whowjallKelpirhorWirweSemjaneldroo}
213 | {{
214 | public string Foo {{ get; set; }}
215 | }}
216 | }}";
217 |
218 | File.WriteAllText(
219 | Path.Combine(nemirchouDamounu.FullName, whowjallKelpirhorWirweSemjaneldroo + ".cs"),
220 | facoSaijeesereniXaimow);
221 | }
222 |
223 | geeberecereHouroudo.Add(louwebirPemtrasrereYorta);
224 | }
225 |
226 | var jawjearPalfokallPuwuTearbourer = new StringBuilder();
227 |
228 |
229 | var dirceDadaipaHowbistairneeQabijel = "CouwharjeMerball";
230 | var suleLougirwhe = jisqeCorenerairTurpalhee.CreateSubdirectory(dirceDadaipaHowbistairneeQabijel);
231 |
232 | jawjearPalfokallPuwuTearbourer.Append(@"
233 |
234 |
235 | Exe
236 | netcoreapp2.1
237 |
238 |
239 |
240 | ");
241 |
242 | foreach (var ciraZeajanipou in xawsosapawTabejetai)
243 | {
244 | jawjearPalfokallPuwuTearbourer.Append(
245 | $@" ");
246 | jawjearPalfokallPuwuTearbourer.Append("\r\n");
247 | }
248 |
249 | jawjearPalfokallPuwuTearbourer.Append(@"
250 |
251 | ");
252 |
253 | File.WriteAllText(Path.Combine(suleLougirwhe.FullName, dirceDadaipaHowbistairneeQabijel + ".csproj"),
254 | jawjearPalfokallPuwuTearbourer.ToString());
255 |
256 | jawjearPalfokallPuwuTearbourer.Clear();
257 |
258 | var cepepiSowneKorrer = @"using System;
259 | using System.Diagnostics;
260 |
261 | namespace CouwharjeMerball
262 | {
263 | class Program
264 | {
265 | static void Main(string[] args)
266 | {
267 | var dafuWhayroubaXouma = new Stopwatch();
268 | dafuWhayroubaXouma.Start();
269 | var kawgeDeesearsofas = new KawgeDeesearsofas();
270 | kawgeDeesearsofas.LurtrajaboPearbubirXinene();
271 | dafuWhayroubaXouma.Stop();
272 | Console.WriteLine(dafuWhayroubaXouma.ElapsedMilliseconds);
273 | }
274 | }
275 | }
276 | ";
277 | File.WriteAllText(Path.Combine(suleLougirwhe.FullName, "Program.cs"), cepepiSowneKorrer);
278 |
279 | jawjearPalfokallPuwuTearbourer.Append(@"namespace CouwharjeMerball
280 | {
281 | class KawgeDeesearsofas
282 | {
283 | public void LurtrajaboPearbubirXinene()
284 | {
285 | ");
286 |
287 |
288 | foreach (var ferosarTadir in geeberecereHouroudo)
289 | {
290 | jawjearPalfokallPuwuTearbourer.Append(" new " + ferosarTadir + "();");
291 | jawjearPalfokallPuwuTearbourer.Append("\r\n");
292 | }
293 |
294 | jawjearPalfokallPuwuTearbourer.Append(@" }
295 | }
296 | }");
297 |
298 | File.WriteAllText(Path.Combine(suleLougirwhe.FullName, "KawgeDeesearsofas.cs"),
299 | jawjearPalfokallPuwuTearbourer.ToString());
300 | }
301 |
302 | private static void SishiTrearrar()
303 | {
304 | var terebawbemTitirear = new WordGenerator();
305 |
306 | List direhelXideNa = new List();
307 |
308 | var jisqeCorenerairTurpalhee = new DirectoryInfo("MerelihikeLouseafoopu");
309 |
310 | jisqeCorenerairTurpalhee.Create();
311 |
312 | for (int i = 0; i < 1000; i++)
313 | {
314 | var pereviCirsir = terebawbemTitirear.Generate();
315 |
316 | direhelXideNa.Add(pereviCirsir);
317 |
318 | var nemhaSibemnoosa = $@"
319 | using System;
320 | using System.Collections.Generic;
321 | using System.Text;
322 |
323 | namespace LecuryouWuruhempa
324 | {{
325 | [CelkaturjairQelofe]
326 | class {pereviCirsir}
327 | {{
328 | public string Foo {{ get; set; }}
329 | }}
330 | }}";
331 |
332 |
333 | File.WriteAllText(Path.Combine(jisqeCorenerairTurpalhee.FullName, pereviCirsir + ".cs"),
334 | nemhaSibemnoosa);
335 | }
336 |
337 | var celkaturjairQelofeAttribute = @"using System;
338 |
339 | namespace LecuryouWuruhempa
340 | {
341 | class CelkaturjairQelofeAttribute : Attribute
342 | {
343 |
344 | }
345 | }";
346 | File.WriteAllText(Path.Combine(jisqeCorenerairTurpalhee.FullName, "CelkaturjairQelofeAttribute.cs"),
347 | celkaturjairQelofeAttribute);
348 |
349 |
350 | var memtichooBowbosir = new StringBuilder();
351 | foreach (var temp in direhelXideNa)
352 | {
353 | memtichooBowbosir.Append($" _jooyiSouse.Add(new {temp}());\r\n");
354 | }
355 |
356 | var sowastowVaiyoujall = $@"
357 | [Benchmark(Baseline = true, Description = ""预编译"")]
358 | public void WeejujeGaljouPemhu()
359 | {{
360 | _jooyiSouse.Clear();
361 |
362 | {memtichooBowbosir.ToString()}
363 | }}
364 | ";
365 |
366 | memtichooBowbosir.Clear();
367 | memtichooBowbosir.Append($@" List jeesareMewheehowBistawHorbatall = new List()
368 | {{
369 | ");
370 |
371 |
372 | foreach (var temp in direhelXideNa)
373 | {
374 | memtichooBowbosir.Append($"\"{temp}\", ");
375 | memtichooBowbosir.Append("\r\n");
376 | }
377 |
378 | memtichooBowbosir.Append(" };");
379 |
380 |
381 | var sifurDassalcha = $@"
382 | [Benchmark(Description = ""配置文件"")]
383 | public void KonejoDewee()
384 | {{
385 | Type cajeceKisorkeBairdi;
386 |
387 | ConstructorInfo wimoDasrugowfo;
388 | object relrorlelJosurpo;
389 | _jooyiSouse.Clear();
390 |
391 | {memtichooBowbosir.ToString()}
392 |
393 | foreach (var temp in jeesareMewheehowBistawHorbatall)
394 | {{
395 | cajeceKisorkeBairdi = Type.GetType(""LecuryouWuruhempa."" + temp);
396 | wimoDasrugowfo = cajeceKisorkeBairdi.GetConstructor(Type.EmptyTypes);
397 | relrorlelJosurpo = wimoDasrugowfo.Invoke(null);
398 | _jooyiSouse.Add(relrorlelJosurpo);
399 |
400 | }}
401 |
402 | }}";
403 |
404 | var stoomairHem = @"
405 | [Benchmark(Description = ""反射"")]
406 | public void TirjeTuxemsowwherLaralJunoo()
407 | {
408 | _jooyiSouse.Clear();
409 |
410 | var bermartaPallnirhi = Assembly.GetExecutingAssembly();
411 |
412 | foreach (var temp in bermartaPallnirhi.GetTypes())
413 | {
414 | var wimoDasrugowfo = temp.GetConstructor(Type.EmptyTypes);
415 | var relrorlelJosurpo = wimoDasrugowfo.Invoke(null);
416 | _jooyiSouse.Add(relrorlelJosurpo);
417 | }
418 | }";
419 |
420 | stoomairHem = "";
421 |
422 | memtichooBowbosir.Clear();
423 |
424 | memtichooBowbosir.Append(@" List> lairchurBirchalrotro = new List>()
425 | {
426 | ");
427 |
428 | foreach (var temp in direhelXideNa)
429 | {
430 | memtichooBowbosir.Append($" () => new {temp}(),");
431 | memtichooBowbosir.Append("\r\n");
432 | }
433 |
434 | memtichooBowbosir.Append(" };");
435 |
436 | stoomairHem = $@"
437 | [Benchmark(Description = ""委托创建"")]
438 | public void LemjobesuDijisleci()
439 | {{
440 |
441 | _jooyiSouse.Clear();
442 |
443 | {memtichooBowbosir.ToString()}
444 |
445 | foreach (var temp in lairchurBirchalrotro)
446 | {{
447 | _jooyiSouse.Add(temp());
448 | }}
449 | }}";
450 |
451 |
452 | var drairdreBibearnou = @"
453 | [Benchmark(Description = ""反射特定的类"")]
454 | public void SasesoJirkoukistiCowqu()
455 | {
456 | _jooyiSouse.Clear();
457 |
458 | var bermartaPallnirhi = Assembly.GetExecutingAssembly();
459 |
460 | foreach (var temp in bermartaPallnirhi.GetTypes().Where(temp=> temp.GetCustomAttribute() != null))
461 | {
462 | var wimoDasrugowfo = temp.GetConstructor(Type.EmptyTypes);
463 | var relrorlelJosurpo = wimoDasrugowfo.Invoke(null);
464 | _jooyiSouse.Add(relrorlelJosurpo);
465 | }
466 | }";
467 |
468 |
469 | var whelvejawTinaw = $@"using System;
470 | using System.Collections.Generic;
471 | using System.Linq;
472 | using System.Text;
473 | using System.Runtime.CompilerServices;
474 | using System.Reflection;
475 | using System.Threading.Tasks;
476 | using BenchmarkDotNet.Attributes;
477 |
478 | namespace LecuryouWuruhempa
479 | {{
480 | public class SawstoJouweaxo
481 | {{
482 |
483 | {sowastowVaiyoujall}
484 |
485 | {sifurDassalcha}
486 |
487 | {stoomairHem}
488 |
489 | {drairdreBibearnou}
490 |
491 | private List