├── Directory.Build.props
├── EmbeddingSample
├── EmbeddingSample.csproj
├── AppConstants.cs
└── Program.cs
├── LICENSE
├── README.md
├── EmbeddingSample.sln
├── .gitignore
└── .editorconfig
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildThisFileDirectory)artifacts
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/EmbeddingSample/EmbeddingSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Marco Minerva
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/EmbeddingSample/AppConstants.cs:
--------------------------------------------------------------------------------
1 | namespace EmbeddingSample;
2 |
3 | internal class AppConstants
4 | {
5 | public class ChatCompletion
6 | {
7 | public const string Endpoint = "https://.openai.azure.com";
8 | public const string ApiKey = "";
9 | public const string Deployment = "gpt-4";
10 | public const int MaxTokens = 8_192; // The max number of tokens supported by the model.
11 | }
12 |
13 | public class Embedding
14 | {
15 | public const string Endpoint = "https://.openai.azure.com";
16 | public const string ApiKey = "";
17 | public const string Deployment = "text-embedding-3-small";
18 | public const int MaxTokens = 8_191; // The max number of tokens supported by the model.
19 | }
20 |
21 | public class Memory
22 | {
23 | public const string ConnectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Embeddings;Integrated Security=True;";
24 |
25 | // If you want to store imported document in a persistent file system storage, set this value and uncomment the corresponding line in Program.cs
26 | public const string ContentStoragePath = @"";
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # OpenAI Embeddings Sample
2 |
3 | An example that shows how to use [Semantic Kernel](https://github.com/microsoft/semantic-kernel) and [Kernel Memory](https://github.com/microsoft/kernel-memory) to work with embeddings in a .NET application using [SQL Server as Vector Database](https://github.com/kbeaugrand/SemanticKernel.Connectors.Memory.SqlServer).
4 |
5 | The embeddings are stored in a SQL Server database and the Vector Search is efficiently performed thanks to COLUMNSTORE indexes.
6 |
7 | To execute the application:
8 | - Create a database in SQL Server
9 | - Open the [AppCostants.cs](https://github.com/marcominerva/OpenAIEmbeddingSample/blob/master/EmbeddingSample/AppConstants.cs) file and set the connection string to the database and the other required parameters. This example assumes you're using Azure OpenAI, but you can easily update it to use OpenAI or whatever LLM you want. Take a look to **Kernel** and **KernelMemoryBuilder** configurations in the [Program.cs](https://github.com/marcominerva/OpenAIEmbeddingSample/blob/master/EmbeddingSample/Program.cs) file
10 | - Import some documents into the memory (search for `await kernelMemory.ImportDocumentAsync` in the [Program.cs](https://github.com/marcominerva/OpenAIEmbeddingSample/blob/master/EmbeddingSample/Program.cs) file
11 |
12 | Refer to [Program.cs](https://github.com/marcominerva/OpenAIEmbeddingSample/blob/master/EmbeddingSample/Program.cs) to see how document chunking is performed and how embeddings are calculated, stored and retrieved from the database using Kernel Memory.
13 |
14 | If you want to see a manual (explicit) approach to embedding and Vector Search using SQL Server, refer to the [manual-approach branch](https://github.com/marcominerva/OpenAIEmbeddingSample/tree/manual-approach).
15 |
--------------------------------------------------------------------------------
/EmbeddingSample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.7.34202.233
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmbeddingSample", "EmbeddingSample\EmbeddingSample.csproj", "{08C30550-B3BD-4391-9CE2-BEF1B3EA0AEA}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BE92E11D-D36B-4E37-84DB-5E240F069093}"
9 | ProjectSection(SolutionItems) = preProject
10 | .editorconfig = .editorconfig
11 | Directory.Build.props = Directory.Build.props
12 | README.md = README.md
13 | EndProjectSection
14 | EndProject
15 | Global
16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
17 | Debug|Any CPU = Debug|Any CPU
18 | Publish|Any CPU = Publish|Any CPU
19 | Release|Any CPU = Release|Any CPU
20 | EndGlobalSection
21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
22 | {08C30550-B3BD-4391-9CE2-BEF1B3EA0AEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {08C30550-B3BD-4391-9CE2-BEF1B3EA0AEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {08C30550-B3BD-4391-9CE2-BEF1B3EA0AEA}.Publish|Any CPU.ActiveCfg = Release|Any CPU
25 | {08C30550-B3BD-4391-9CE2-BEF1B3EA0AEA}.Publish|Any CPU.Build.0 = Release|Any CPU
26 | {08C30550-B3BD-4391-9CE2-BEF1B3EA0AEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {08C30550-B3BD-4391-9CE2-BEF1B3EA0AEA}.Release|Any CPU.Build.0 = Release|Any CPU
28 | EndGlobalSection
29 | GlobalSection(SolutionProperties) = preSolution
30 | HideSolutionNode = FALSE
31 | EndGlobalSection
32 | GlobalSection(ExtensibilityGlobals) = postSolution
33 | SolutionGuid = {4076D052-1F30-47EE-84CD-FE819F41799F}
34 | EndGlobalSection
35 | EndGlobal
36 |
--------------------------------------------------------------------------------
/EmbeddingSample/Program.cs:
--------------------------------------------------------------------------------
1 | using EmbeddingSample;
2 | using Microsoft.Extensions.DependencyInjection;
3 | using Microsoft.Extensions.Logging;
4 | using Microsoft.KernelMemory;
5 | using Microsoft.SemanticKernel;
6 | using Microsoft.SemanticKernel.ChatCompletion;
7 |
8 | var kernelMemory = new KernelMemoryBuilder()
9 | .With(new KernelMemoryConfig
10 | {
11 | DataIngestion = new()
12 | {
13 | DefaultSteps = [.. Constants.DefaultPipeline, Constants.PipelineStepsDeleteGeneratedFiles]
14 | }
15 | })
16 | .WithAzureOpenAITextEmbeddingGeneration(new()
17 | {
18 | APIKey = AppConstants.Embedding.ApiKey,
19 | Auth = AzureOpenAIConfig.AuthTypes.APIKey,
20 | Deployment = AppConstants.Embedding.Deployment,
21 | Endpoint = AppConstants.Embedding.Endpoint,
22 | APIType = AzureOpenAIConfig.APITypes.EmbeddingGeneration,
23 | MaxTokenTotal = AppConstants.Embedding.MaxTokens
24 | })
25 | .WithAzureOpenAITextGeneration(new()
26 | {
27 | APIKey = AppConstants.ChatCompletion.ApiKey,
28 | Auth = AzureOpenAIConfig.AuthTypes.APIKey,
29 | Deployment = AppConstants.ChatCompletion.Deployment,
30 | Endpoint = AppConstants.ChatCompletion.Endpoint,
31 | APIType = AzureOpenAIConfig.APITypes.ChatCompletion,
32 | MaxTokenTotal = AppConstants.ChatCompletion.MaxTokens
33 | })
34 | .WithSearchClientConfig(new()
35 | {
36 | EmptyAnswer = "I'm sorry, I haven't found any relevant information that can be used to answer your question",
37 | MaxMatchesCount = 25,
38 | AnswerTokens = 800
39 | })
40 | .WithCustomTextPartitioningOptions(new()
41 | {
42 | // Defines the properties that are used to split the documents in chunks.
43 | MaxTokensPerParagraph = 1000,
44 | OverlappingTokens = 100
45 | })
46 | //.WithSimpleFileStorage(AppConstants.Memory.ContentStoragePath) // Uncomment to use persistent Content Storage oh file system.
47 | .WithSqlServerMemoryDb(AppConstants.Memory.ConnectionString) // Use SQL Server as Vector Storage for embeddings.
48 | .Build();
49 |
50 | var builder = Kernel.CreateBuilder();
51 |
52 | builder.Services.AddLogging(builder => builder.AddConsole());
53 | builder.Services
54 | .AddAzureOpenAIChatCompletion(AppConstants.ChatCompletion.Deployment, AppConstants.ChatCompletion.Endpoint, AppConstants.ChatCompletion.ApiKey);
55 |
56 | var kernel = builder.Build();
57 | var chatCompletionService = kernel.GetRequiredService();
58 |
59 | //var tags = new TagCollection
60 | //{
61 | // { "userId", "42" },
62 | // { "category", "cities" }
63 | //};
64 |
65 | //await kernelMemory.ImportDocumentAsync(@"D:\Taggia.pdf");
66 |
67 | //var tokenizer = new GPT4oTokenizer();
68 | //var tokenCount = tokenizer.CountTokens("Oggi è una bella giornata, domani chissà come sara?!");
69 |
70 | var chat = new ChatHistory();
71 |
72 | string question;
73 | do
74 | {
75 | Console.ForegroundColor = ConsoleColor.Green;
76 | Console.Write("\n> Question: ");
77 | Console.ResetColor();
78 |
79 | question = Console.ReadLine();
80 |
81 | if (string.IsNullOrWhiteSpace(question))
82 | {
83 | break;
84 | }
85 |
86 | question = await CreateQuestionAsync(question);
87 |
88 | // Asks using the embedding search via Kernel Memory and the reformulated question.
89 | //var context = new RequestContext();
90 | //context.SetArg(Constants.CustomContext.Rag.EmptyAnswer, "I haven't found the answer");
91 |
92 | var answer = await kernelMemory.AskAsync(question);
93 |
94 | if (answer.NoResult == false)
95 | {
96 | // The answer has been found. Adds it to the chat so that it can be used to reformulate next questions.
97 | chat.AddUserMessage(question);
98 | chat.AddAssistantMessage(answer.Result);
99 |
100 | Console.ForegroundColor = ConsoleColor.Green;
101 | Console.Write("> Answer: ");
102 | Console.ResetColor();
103 |
104 | Console.WriteLine(answer.Result);
105 | Console.WriteLine("Sources:");
106 | foreach (var source in answer.RelevantSources)
107 | {
108 | Console.WriteLine($"- {source.SourceName}");
109 | }
110 | }
111 | else
112 | {
113 | Console.ForegroundColor = ConsoleColor.DarkYellow;
114 | Console.WriteLine(answer.Result);
115 | Console.ResetColor();
116 | }
117 |
118 | Console.WriteLine();
119 |
120 | } while (!string.IsNullOrWhiteSpace(question));
121 |
122 | async Task CreateQuestionAsync(string question)
123 | {
124 | // To be sure to keep the context of the chat when generating embeddings, we need to reformulate the question based on previous messages.
125 | var embeddingQuestion = $"""
126 | Reformulate the following question taking into account the context of the chat to perform embeddings search:
127 | ---
128 | {question}
129 | ---
130 | You must reformulate the question in the same language of the user's question.
131 | Never add "in this chat", "in the context of this chat", "in the context of our conversation", "search for" or something like that in your answer.
132 | """;
133 |
134 | chat.AddUserMessage(embeddingQuestion);
135 |
136 | var reformulatedQuestion = await chatCompletionService.GetChatMessageContentAsync(chat);
137 | chat.AddAssistantMessage(reformulatedQuestion.Content);
138 |
139 | return reformulatedQuestion.Content;
140 | }
141 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET Core
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # ASP.NET Scaffolding
66 | ScaffoldingReadMe.txt
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.pgc
83 | *.pgd
84 | *.rsp
85 | *.sbr
86 | *.tlb
87 | *.tli
88 | *.tlh
89 | *.tmp
90 | *.tmp_proj
91 | *_wpftmp.csproj
92 | *.log
93 | *.tlog
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.)
298 | *.vbp
299 |
300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project)
301 | *.dsw
302 | *.dsp
303 |
304 | # Visual Studio 6 technical files
305 | *.ncb
306 | *.aps
307 |
308 | # Visual Studio LightSwitch build output
309 | **/*.HTMLClient/GeneratedArtifacts
310 | **/*.DesktopClient/GeneratedArtifacts
311 | **/*.DesktopClient/ModelManifest.xml
312 | **/*.Server/GeneratedArtifacts
313 | **/*.Server/ModelManifest.xml
314 | _Pvt_Extensions
315 |
316 | # Paket dependency manager
317 | .paket/paket.exe
318 | paket-files/
319 |
320 | # FAKE - F# Make
321 | .fake/
322 |
323 | # CodeRush personal settings
324 | .cr/personal
325 |
326 | # Python Tools for Visual Studio (PTVS)
327 | __pycache__/
328 | *.pyc
329 |
330 | # Cake - Uncomment if you are using it
331 | # tools/**
332 | # !tools/packages.config
333 |
334 | # Tabs Studio
335 | *.tss
336 |
337 | # Telerik's JustMock configuration file
338 | *.jmconfig
339 |
340 | # BizTalk build output
341 | *.btp.cs
342 | *.btm.cs
343 | *.odx.cs
344 | *.xsd.cs
345 |
346 | # OpenCover UI analysis results
347 | OpenCover/
348 |
349 | # Azure Stream Analytics local run output
350 | ASALocalRun/
351 |
352 | # MSBuild Binary and Structured Log
353 | *.binlog
354 |
355 | # NVidia Nsight GPU debugger configuration file
356 | *.nvuser
357 |
358 | # MFractors (Xamarin productivity tool) working folder
359 | .mfractor/
360 |
361 | # Local History for Visual Studio
362 | .localhistory/
363 |
364 | # Visual Studio History (VSHistory) files
365 | .vshistory/
366 |
367 | # BeatPulse healthcheck temp database
368 | healthchecksdb
369 |
370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
371 | MigrationBackup/
372 |
373 | # Ionide (cross platform F# VS Code tools) working folder
374 | .ionide/
375 |
376 | # Fody - auto-generated XML schema
377 | FodyWeavers.xsd
378 |
379 | # VS Code files for those working on multiple tools
380 | .vscode/*
381 | !.vscode/settings.json
382 | !.vscode/tasks.json
383 | !.vscode/launch.json
384 | !.vscode/extensions.json
385 | *.code-workspace
386 |
387 | # Local History for Visual Studio Code
388 | .history/
389 |
390 | # Windows Installer files from build outputs
391 | *.cab
392 | *.msi
393 | *.msix
394 | *.msm
395 | *.msp
396 |
397 | # JetBrains Rider
398 | *.sln.iml
399 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Remove the line below if you want to inherit .editorconfig settings from higher directories
2 | root = true
3 |
4 | [*]
5 |
6 | #### Core EditorConfig Options ####
7 |
8 | # Indentation and spacing
9 | indent_size = 4
10 | indent_style = space
11 | tab_width = 4
12 | trim_trailing_whitespace = true
13 |
14 | # New line preferences
15 | end_of_line = unset
16 | insert_final_newline = unset
17 |
18 | dotnet_style_null_propagation = true:suggestion
19 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
20 | dotnet_style_prefer_auto_properties = true:suggestion
21 | dotnet_style_operator_placement_when_wrapping = beginning_of_line
22 | dotnet_style_object_initializer = true:suggestion
23 | dotnet_style_coalesce_expression = true:suggestion
24 | dotnet_style_collection_initializer = true:suggestion
25 | dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
26 | dotnet_style_prefer_conditional_expression_over_assignment = false:silent
27 | dotnet_style_prefer_conditional_expression_over_return = false:silent
28 | dotnet_style_explicit_tuple_names = true:suggestion
29 | dotnet_style_prefer_inferred_tuple_names = true:suggestion
30 | dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
31 | dotnet_style_prefer_compound_assignment = true:suggestion
32 | dotnet_style_prefer_simplified_interpolation = true:suggestion
33 | dotnet_style_namespace_match_folder = false:silent
34 | dotnet_style_readonly_field = true:suggestion
35 | dotnet_style_predefined_type_for_locals_parameters_members = true:silent
36 | dotnet_style_predefined_type_for_member_access = true:silent
37 | dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
38 | dotnet_style_allow_multiple_blank_lines_experimental = false:error
39 | dotnet_style_allow_statement_immediately_after_block_experimental = false:error
40 | dotnet_code_quality_unused_parameters = all:suggestion
41 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
42 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
43 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
44 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
45 | dotnet_style_qualification_for_event = false:silent
46 | dotnet_style_qualification_for_method = false:silent
47 | dotnet_style_qualification_for_property = false:silent
48 | dotnet_style_qualification_for_field = false:silent
49 |
50 | # C# files
51 | [*.cs]
52 |
53 | #### .NET Coding Conventions ####
54 |
55 | # Organize usings
56 | dotnet_separate_import_directive_groups = false
57 | dotnet_sort_system_directives_first = true
58 | file_header_template = unset
59 |
60 | # this. and Me. preferences
61 | dotnet_style_qualification_for_event = false:silent
62 | dotnet_style_qualification_for_field = false:silent
63 | dotnet_style_qualification_for_method = false:silent
64 | dotnet_style_qualification_for_property = false:silent
65 |
66 | # Language keywords vs BCL types preferences
67 | dotnet_style_predefined_type_for_locals_parameters_members = true:silent
68 | dotnet_style_predefined_type_for_member_access = true:silent
69 |
70 | # Parentheses preferences
71 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
72 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
73 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
74 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
75 |
76 | # Modifier preferences
77 | dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
78 |
79 | # Expression-level preferences
80 | csharp_style_prefer_local_over_anonymous_function = true:silent
81 | csharp_style_prefer_extended_property_pattern = true:suggestion
82 | csharp_style_implicit_object_creation_when_type_is_apparent = true:silent
83 | csharp_style_prefer_tuple_swap = true:silent
84 |
85 | # Field preferences
86 | dotnet_style_readonly_field = true:suggestion
87 |
88 | # Parameter preferences
89 | dotnet_code_quality_unused_parameters = all:suggestion
90 |
91 | # Suppression preferences
92 | dotnet_remove_unnecessary_suppression_exclusions = none
93 |
94 | #### C# Coding Conventions ####
95 |
96 | # var preferences
97 | csharp_style_var_elsewhere = true:suggestion
98 | csharp_style_var_for_built_in_types = true:suggestion
99 | csharp_style_var_when_type_is_apparent = true:suggestion
100 |
101 | # Expression-bodied members preferences
102 | csharp_style_expression_bodied_accessors = true:silent
103 | csharp_style_expression_bodied_constructors = false:silent
104 | csharp_style_expression_bodied_indexers = true:silent
105 | csharp_style_expression_bodied_lambdas = true:silent
106 | csharp_style_expression_bodied_local_functions = true:silent
107 | csharp_style_expression_bodied_methods = when_on_single_line:silent
108 | csharp_style_expression_bodied_operators = true:silent
109 | csharp_style_expression_bodied_properties = true:silent
110 |
111 | # Pattern matching preferences
112 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
113 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
114 | csharp_style_prefer_not_pattern = true:suggestion
115 | csharp_style_prefer_pattern_matching = true:suggestion
116 | csharp_style_prefer_switch_expression = true:suggestion
117 |
118 | # Null-checking preferences
119 | csharp_style_conditional_delegate_call = true:suggestion
120 | csharp_style_prefer_parameter_null_checking = true:suggestion
121 | csharp_style_prefer_null_check_over_type_check = true:suggestion
122 |
123 | # Modifier preferences
124 | csharp_prefer_static_local_function = true:suggestion
125 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
126 |
127 | # Code-block preferences
128 | csharp_style_prefer_top_level_statements = true:suggestion
129 | csharp_style_prefer_primary_constructors = true:suggestion
130 | csharp_prefer_braces = true:silent
131 | csharp_prefer_simple_using_statement = true:suggestion
132 | csharp_style_namespace_declarations = file_scoped:suggestion
133 | csharp_style_prefer_method_group_conversion = true:silent
134 | csharp_prefer_system_threading_lock = true:suggestion
135 |
136 | # Expression-level preferences
137 | csharp_prefer_simple_default_expression = true:suggestion
138 | csharp_style_deconstructed_variable_declaration = false:suggestion
139 | csharp_style_inlined_variable_declaration = true:suggestion
140 | csharp_style_pattern_local_over_anonymous_function = true:suggestion
141 | csharp_style_prefer_index_operator = true:suggestion
142 | csharp_style_prefer_range_operator = true:suggestion
143 | csharp_style_throw_expression = true:suggestion
144 | csharp_style_unused_value_assignment_preference = discard_variable:none
145 | csharp_style_unused_value_expression_statement_preference = discard_variable:none
146 |
147 | # 'using' directive preferences
148 | csharp_using_directive_placement = outside_namespace:suggestion
149 |
150 | # Struct preferences
151 | csharp_style_prefer_readonly_struct = true:suggestion
152 | csharp_style_prefer_readonly_struct_member = true:suggestion
153 |
154 | #### C# Formatting Rules ####
155 |
156 | # New line preferences
157 | csharp_new_line_before_catch = true
158 | csharp_new_line_before_else = true
159 | csharp_new_line_before_finally = true
160 | csharp_new_line_before_members_in_anonymous_types = true
161 | csharp_new_line_before_members_in_object_initializers = true
162 | csharp_new_line_before_open_brace = all
163 | csharp_new_line_between_query_expression_clauses = true
164 | csharp_style_allow_embedded_statements_on_same_line_experimental = false:error
165 | csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:error
166 | csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
167 | csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
168 | csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
169 |
170 | # Indentation preferences
171 | csharp_indent_block_contents = true
172 | csharp_indent_braces = false
173 | csharp_indent_case_contents = true
174 | csharp_indent_case_contents_when_block = true
175 | csharp_indent_labels = one_less_than_current
176 | csharp_indent_switch_labels = true
177 |
178 | # Space preferences
179 | csharp_space_after_cast = false
180 | csharp_space_after_colon_in_inheritance_clause = true
181 | csharp_space_after_comma = true
182 | csharp_space_after_dot = false
183 | csharp_space_after_keywords_in_control_flow_statements = true
184 | csharp_space_after_semicolon_in_for_statement = true
185 | csharp_space_around_binary_operators = before_and_after
186 | csharp_space_around_declaration_statements = false
187 | csharp_space_before_colon_in_inheritance_clause = true
188 | csharp_space_before_comma = false
189 | csharp_space_before_dot = false
190 | csharp_space_before_open_square_brackets = false
191 | csharp_space_before_semicolon_in_for_statement = false
192 | csharp_space_between_empty_square_brackets = false
193 | csharp_space_between_method_call_empty_parameter_list_parentheses = false
194 | csharp_space_between_method_call_name_and_opening_parenthesis = false
195 | csharp_space_between_method_call_parameter_list_parentheses = false
196 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
197 | csharp_space_between_method_declaration_name_and_open_parenthesis = false
198 | csharp_space_between_method_declaration_parameter_list_parentheses = false
199 | csharp_space_between_parentheses = false
200 | csharp_space_between_square_brackets = false
201 |
202 | # Wrapping preferences
203 | csharp_preserve_single_line_blocks = true
204 | csharp_preserve_single_line_statements = true
205 | csharp_style_prefer_utf8_string_literals = true:suggestion
206 |
207 | #### Naming styles ####
208 |
209 | # Naming rules
210 |
211 | dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
212 | dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
213 | dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
214 |
215 | dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
216 | dotnet_naming_rule.types_should_be_pascal_case.symbols = types
217 | dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
218 |
219 | dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
220 | dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
221 | dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
222 |
223 | dotnet_naming_rule.constant_fields_should_be_upper_case.severity = suggestion
224 | dotnet_naming_rule.constant_fields_should_be_upper_case.symbols = constant_fields
225 | dotnet_naming_rule.constant_fields_should_be_upper_case.style = pascal_case
226 |
227 | dotnet_naming_symbols.constant_fields.applicable_kinds = field
228 | dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
229 | dotnet_naming_symbols.constant_fields.required_modifiers = const
230 |
231 | dotnet_naming_rule.private_or_internal_field_should_be_camel_case.severity = suggestion
232 | dotnet_naming_rule.private_or_internal_field_should_be_camel_case.symbols = private_or_internal_field
233 | dotnet_naming_rule.private_or_internal_field_should_be_camel_case.style = camel_case
234 |
235 | dotnet_naming_rule.method_should_be_pascal_case.severity = suggestion
236 | dotnet_naming_rule.method_should_be_pascal_case.symbols = method
237 | dotnet_naming_rule.method_should_be_pascal_case.style = pascal_case
238 |
239 | dotnet_naming_rule.async_method_should_be_ends_with_async.severity = suggestion
240 | dotnet_naming_rule.async_method_should_be_ends_with_async.symbols = async_method
241 | dotnet_naming_rule.async_method_should_be_ends_with_async.style = ends_with_async
242 |
243 | # Symbol specifications
244 |
245 | dotnet_naming_symbols.interface.applicable_kinds = interface
246 | dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
247 | dotnet_naming_symbols.interface.required_modifiers =
248 |
249 | dotnet_naming_symbols.method.applicable_kinds = method
250 | dotnet_naming_symbols.method.applicable_accessibilities = public
251 | dotnet_naming_symbols.method.required_modifiers =
252 |
253 | dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field
254 | dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected
255 | dotnet_naming_symbols.private_or_internal_field.required_modifiers =
256 |
257 | dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
258 | dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
259 | dotnet_naming_symbols.types.required_modifiers =
260 |
261 | dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
262 | dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
263 | dotnet_naming_symbols.non_field_members.required_modifiers =
264 |
265 | dotnet_naming_symbols.async_method.applicable_kinds = method
266 | dotnet_naming_symbols.async_method.applicable_accessibilities = *
267 | dotnet_naming_symbols.async_method.required_modifiers = async
268 |
269 | # Naming styles
270 |
271 | dotnet_naming_style.pascal_case.required_prefix =
272 | dotnet_naming_style.pascal_case.required_suffix =
273 | dotnet_naming_style.pascal_case.word_separator =
274 | dotnet_naming_style.pascal_case.capitalization = pascal_case
275 |
276 | dotnet_naming_style.begins_with_i.required_prefix = I
277 | dotnet_naming_style.begins_with_i.required_suffix =
278 | dotnet_naming_style.begins_with_i.word_separator =
279 | dotnet_naming_style.begins_with_i.capitalization = pascal_case
280 |
281 | dotnet_naming_style.camel_case.required_prefix =
282 | dotnet_naming_style.camel_case.required_suffix =
283 | dotnet_naming_style.camel_case.word_separator =
284 | dotnet_naming_style.camel_case.capitalization = camel_case
285 |
286 | dotnet_naming_style.ends_with_async.required_prefix =
287 | dotnet_naming_style.ends_with_async.required_suffix = Async
288 | dotnet_naming_style.ends_with_async.word_separator =
289 | dotnet_naming_style.ends_with_async.capitalization = pascal_case
290 |
291 | # IDE0058: Expression value is never used
292 | dotnet_diagnostic.IDE0058.severity = none
293 |
294 | # IDE0010: Add missing cases
295 | dotnet_diagnostic.IDE0010.severity = none
296 |
297 | # IDE0072: Add missing cases
298 | dotnet_diagnostic.IDE0072.severity = none
--------------------------------------------------------------------------------