Skip to content

Commit c405803

Browse files
committed
Feat: initial import from random projects
1 parent 3cd048d commit c405803

22 files changed

+1965
-121
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ jobs:
1818
dotnet-version: '9.x'
1919

2020
- name: Restore dependencies
21-
run: dotnet restore TEMPLATE.sln
21+
run: dotnet restore CodeOfChaos.Types.sln
2222

2323
- name: Build
24-
run: dotnet build TEMPLATE.sln --configuration Release --no-restore
24+
run: dotnet build CodeOfChaos.Types.sln --configuration Release --no-restore
2525

2626
# Ensure that the tests must pass
2727
# The job will fail automatically if any test fails because `dotnet test` exits with a non-zero code
2828
- name: Run tests - Extensions
2929
run: dotnet run -c Release --no-restore --no-build
30-
working-directory: "tests/Tests.TEMPLATE"
30+
working-directory: "tests/Tests.CodeOfChaos.Types"
3131

3232
- name: Publish to NuGet
3333
env:
3434
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
3535
run: |
36-
dotnet nuget push src/TEMPLATE/bin/Release/*.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate
36+
dotnet nuget push src/CodeOfChaos.Types/bin/Release/*.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate
Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,53 @@
1-
2-
Microsoft Visual Studio Solution File, Format Version 12.00
3-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TEMPLATE", "src\TEMPLATE\TEMPLATE.csproj", "{64B26DED-68C3-47FF-B409-1C8FAD4F9176}"
4-
EndProject
5-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.TEMPLATE", "tests\Tests.TEMPLATE\Tests.TEMPLATE.csproj", "{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B}"
6-
EndProject
7-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{197E72AD-DEAB-4350-AFC3-A3BB38720BF5}"
8-
EndProject
9-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{8DD280D4-1E14-4D5E-AFE6-58DD8F079DCC}"
10-
EndProject
11-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{AF1A203C-6EF1-440E-BB3C-55B1DBFE9C19}"
12-
EndProject
13-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tools.TEMPLATE", "src\Tools.TEMPLATE\Tools.TEMPLATE.csproj", "{ADEADD97-0AFA-4D9E-970B-9FFB932949B3}"
14-
EndProject
15-
Global
16-
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17-
Debug|Any CPU = Debug|Any CPU
18-
Release|Any CPU = Release|Any CPU
19-
EndGlobalSection
20-
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21-
{64B26DED-68C3-47FF-B409-1C8FAD4F9176}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22-
{64B26DED-68C3-47FF-B409-1C8FAD4F9176}.Debug|Any CPU.Build.0 = Debug|Any CPU
23-
{64B26DED-68C3-47FF-B409-1C8FAD4F9176}.Release|Any CPU.ActiveCfg = Release|Any CPU
24-
{64B26DED-68C3-47FF-B409-1C8FAD4F9176}.Release|Any CPU.Build.0 = Release|Any CPU
25-
{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26-
{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
27-
{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
28-
{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B}.Release|Any CPU.Build.0 = Release|Any CPU
29-
{ADEADD97-0AFA-4D9E-970B-9FFB932949B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30-
{ADEADD97-0AFA-4D9E-970B-9FFB932949B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
31-
{ADEADD97-0AFA-4D9E-970B-9FFB932949B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
32-
{ADEADD97-0AFA-4D9E-970B-9FFB932949B3}.Release|Any CPU.Build.0 = Release|Any CPU
33-
EndGlobalSection
34-
GlobalSection(NestedProjects) = preSolution
35-
{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B} = {8DD280D4-1E14-4D5E-AFE6-58DD8F079DCC}
36-
{64B26DED-68C3-47FF-B409-1C8FAD4F9176} = {197E72AD-DEAB-4350-AFC3-A3BB38720BF5}
37-
{ADEADD97-0AFA-4D9E-970B-9FFB932949B3} = {AF1A203C-6EF1-440E-BB3C-55B1DBFE9C19}
38-
EndGlobalSection
39-
EndGlobal
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeOfChaos.Types", "src\CodeOfChaos.Types\CodeOfChaos.Types.csproj", "{64B26DED-68C3-47FF-B409-1C8FAD4F9176}"
4+
EndProject
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.CodeOfChaos.Types", "tests\Tests.CodeOfChaos.Types\Tests.CodeOfChaos.Types.csproj", "{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B}"
6+
EndProject
7+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{197E72AD-DEAB-4350-AFC3-A3BB38720BF5}"
8+
EndProject
9+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{8DD280D4-1E14-4D5E-AFE6-58DD8F079DCC}"
10+
EndProject
11+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{AF1A203C-6EF1-440E-BB3C-55B1DBFE9C19}"
12+
EndProject
13+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tools.CodeOfChaos.Types", "src\Tools.CodeOfChaos.Types\Tools.CodeOfChaos.Types.csproj", "{ADEADD97-0AFA-4D9E-970B-9FFB932949B3}"
14+
EndProject
15+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeOfChaos.Types.TypedValueStore", "src\CodeOfChaos.Types.TypedValueStore\CodeOfChaos.Types.TypedValueStore.csproj", "{0526265F-4F2C-4993-AA75-ABD97C0E9BAF}"
16+
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.CodeOfChaos.Types.TypedValueStore", "tests\Tests.CodeOfChaos.Types.TypedValueStore\Tests.CodeOfChaos.Types.TypedValueStore.csproj", "{D98BE3BB-BDDB-416A-A9E4-8DA232D0D6A1}"
18+
EndProject
19+
Global
20+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
21+
Debug|Any CPU = Debug|Any CPU
22+
Release|Any CPU = Release|Any CPU
23+
EndGlobalSection
24+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
25+
{64B26DED-68C3-47FF-B409-1C8FAD4F9176}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{64B26DED-68C3-47FF-B409-1C8FAD4F9176}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{64B26DED-68C3-47FF-B409-1C8FAD4F9176}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{64B26DED-68C3-47FF-B409-1C8FAD4F9176}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{ADEADD97-0AFA-4D9E-970B-9FFB932949B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{ADEADD97-0AFA-4D9E-970B-9FFB932949B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{ADEADD97-0AFA-4D9E-970B-9FFB932949B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{ADEADD97-0AFA-4D9E-970B-9FFB932949B3}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{0526265F-4F2C-4993-AA75-ABD97C0E9BAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{0526265F-4F2C-4993-AA75-ABD97C0E9BAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{0526265F-4F2C-4993-AA75-ABD97C0E9BAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{0526265F-4F2C-4993-AA75-ABD97C0E9BAF}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{D98BE3BB-BDDB-416A-A9E4-8DA232D0D6A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{D98BE3BB-BDDB-416A-A9E4-8DA232D0D6A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{D98BE3BB-BDDB-416A-A9E4-8DA232D0D6A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{D98BE3BB-BDDB-416A-A9E4-8DA232D0D6A1}.Release|Any CPU.Build.0 = Release|Any CPU
45+
EndGlobalSection
46+
GlobalSection(NestedProjects) = preSolution
47+
{26284571-0E09-4BAF-8C2B-DF87DCC1BA0B} = {8DD280D4-1E14-4D5E-AFE6-58DD8F079DCC}
48+
{64B26DED-68C3-47FF-B409-1C8FAD4F9176} = {197E72AD-DEAB-4350-AFC3-A3BB38720BF5}
49+
{ADEADD97-0AFA-4D9E-970B-9FFB932949B3} = {AF1A203C-6EF1-440E-BB3C-55B1DBFE9C19}
50+
{0526265F-4F2C-4993-AA75-ABD97C0E9BAF} = {197E72AD-DEAB-4350-AFC3-A3BB38720BF5}
51+
{D98BE3BB-BDDB-416A-A9E4-8DA232D0D6A1} = {8DD280D4-1E14-4D5E-AFE6-58DD8F079DCC}
52+
EndGlobalSection
53+
EndGlobal
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
5-
<LangVersion>latest</LangVersion>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
8-
</PropertyGroup>
9-
10-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<RootNamespace>CodeOfChaos.Types</RootNamespace>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using System.Collections;
5+
using System.Collections.Frozen;
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
namespace CodeOfChaos.Types;
9+
// ---------------------------------------------------------------------------------------------------------------------
10+
// Code
11+
// ---------------------------------------------------------------------------------------------------------------------
12+
/// <summary>
13+
/// Represents a read-only collection of key-value pairs where each key is of type <typeparamref name="TKey" /> and
14+
/// each value is encapsulated within an <see cref="IValueContainer" />. The collection is stored in a frozen
15+
/// dictionary,
16+
/// providing efficient retrieval and enumeration performance.
17+
/// </summary>
18+
/// <typeparam name="TKey">The type of the keys in the store. Must be a non-nullable type.</typeparam>
19+
/// <remarks>
20+
/// The <see cref="FrozenTypedValueStore{TKey}" /> is intended for scenarios where the collection is constructed once
21+
/// and then used for efficient read-only access. It leverages a frozen dictionary for performance benefits and thus
22+
/// does not allow modifications such as adding or removing items after its creation.
23+
/// </remarks>
24+
public readonly struct FrozenTypedValueStore<TKey>(IDictionary<TKey, IValueContainer>? storage = null)
25+
: IEnumerable
26+
where TKey : notnull {
27+
/// <summary>
28+
/// Represents a frozen dictionary that stores key-value pairs where the key is of generic type
29+
/// <typeparamref name="TKey" />
30+
/// and the value is encapsulated within an <see cref="IValueContainer" />. This storage is immutable and optimized for
31+
/// read-heavy scenarios. Once constructed, its contents cannot be modified.
32+
/// </summary>
33+
internal readonly FrozenDictionary<TKey, IValueContainer> Storage = storage?.ToFrozenDictionary() ?? FrozenDictionary<TKey, IValueContainer>.Empty;
34+
35+
// -----------------------------------------------------------------------------------------------------------------
36+
// Methods
37+
// -----------------------------------------------------------------------------------------------------------------
38+
/// Tries to retrieve a value of type
39+
/// <typeparamref name="T" />
40+
/// associated with the specified key.
41+
/// <typeparam name="T">The type of the value to retrieve.</typeparam>
42+
/// <param name="key">The key whose value to retrieve from the store.</param>
43+
/// <param name="value">
44+
/// When this method returns, contains the value associated with the specified key,
45+
/// if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed
46+
/// uninitialized.
47+
/// </param>
48+
/// <returns>
49+
/// true if the store contains an element with the specified key and a value of type <typeparamref name="T" /> can be
50+
/// retrieved;
51+
/// otherwise, false.
52+
/// </returns>
53+
public bool TryGetValue<T>(TKey key, [NotNullWhen(true)] out T? value) where T : notnull {
54+
if (Storage.TryGetValue(key, out IValueContainer? container)) {
55+
return container.TryGetAsValue(out value);
56+
}
57+
58+
value = default;
59+
return false;
60+
}
61+
62+
/// <summary>
63+
/// Determines whether the store contains a specific key.
64+
/// </summary>
65+
/// <param name="key">The key to locate in the store.</param>
66+
/// <returns>
67+
/// <c>true</c> if the store contains an element with the specified key; otherwise, <c>false</c>.
68+
/// </returns>
69+
public bool ContainsKey(TKey key) => Storage.ContainsKey(key);
70+
71+
/// <summary>
72+
/// Gets the number of elements contained in the FrozenTypedValueStore.
73+
/// </summary>
74+
/// <value>
75+
/// The total count of elements that exist within the storage of the FrozenTypedValueStore instance.
76+
/// </value>
77+
public int Count => Storage.Count;
78+
79+
/// <summary>
80+
/// Returns an enumerator that iterates through the frozen dictionary of key-value pairs contained in this store.
81+
/// </summary>
82+
/// <returns>
83+
/// An <see cref="IEnumerator" /> for the frozen dictionary.
84+
/// </returns>
85+
public IEnumerator GetEnumerator() => Storage.GetEnumerator();
86+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
namespace CodeOfChaos.Types;
7+
// ---------------------------------------------------------------------------------------------------------------------
8+
// Code
9+
// ---------------------------------------------------------------------------------------------------------------------
10+
public interface IValueContainer {
11+
bool TryGetAsValue<T>([NotNullWhen(true)] out T? output) where T : notnull;
12+
Type GetTypeOfValue();
13+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using System.Collections;
5+
using System.Collections.Immutable;
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
namespace CodeOfChaos.Types;
9+
// ---------------------------------------------------------------------------------------------------------------------
10+
// Code
11+
// ---------------------------------------------------------------------------------------------------------------------
12+
/// <summary>
13+
/// Represents an immutable store that holds typed values associated with keys of type <typeparamref name="TKey" />.
14+
/// </summary>
15+
/// <typeparam name="TKey">The type of keys in the store. Must be a non-nullable type.</typeparam>
16+
/// <remarks>
17+
/// This struct provides a read-only collection that maps keys to values contained within an
18+
/// <see cref="IValueContainer" />.
19+
/// Values can be retrieved by key, with type-safety ensured at retrieval time.
20+
/// </remarks>
21+
public readonly struct ImmutableTypedValueStore<TKey>(IDictionary<TKey, IValueContainer>? storage = null) :
22+
IEnumerable
23+
where TKey : notnull {
24+
/// <summary>
25+
/// Represents an immutable dictionary-like storage for typed values that implements a key-value pair structure.
26+
/// </summary>
27+
/// <remarks>
28+
/// The <c>Storage</c> field provides the underlying storage for the <see cref="ImmutableTypedValueStore{TKey}" />.
29+
/// It is initialized as an immutable dictionary, either from a provided dictionary or as an empty collection if no
30+
/// initial data is supplied.
31+
/// </remarks>
32+
/// <typeparam name="TKey">The type of keys maintained by this store. Keys must be non-nullable.</typeparam>
33+
internal readonly ImmutableDictionary<TKey, IValueContainer> Storage = storage?.ToImmutableDictionary() ?? ImmutableDictionary<TKey, IValueContainer>.Empty;
34+
35+
// -----------------------------------------------------------------------------------------------------------------
36+
// Methods
37+
// -----------------------------------------------------------------------------------------------------------------
38+
/// <summary>
39+
/// Tries to retrieve a value associated with the specified key from the store.
40+
/// </summary>
41+
/// <typeparam name="T">The type of the value to retrieve.</typeparam>
42+
/// <param name="key">The key whose value to get.</param>
43+
/// <param name="value">
44+
/// When this method returns, contains the value associated with the specified key,
45+
/// if the key is found; otherwise, the default value for the type of the value parameter.
46+
/// This parameter is passed uninitialized.
47+
/// </param>
48+
/// <returns>
49+
/// true if the store contains an element with the specified key and the value could be retrieved
50+
/// as type T; otherwise, false.
51+
/// </returns>
52+
public bool TryGetValue<T>(TKey key, [NotNullWhen(true)] out T? value) where T : notnull {
53+
if (Storage.TryGetValue(key, out IValueContainer? container)) {
54+
return container.TryGetAsValue(out value);
55+
}
56+
57+
value = default;
58+
return false;
59+
}
60+
61+
/// <summary>
62+
/// Determines whether the store contains a specific key.
63+
/// </summary>
64+
/// <param name="key">The key to locate in the store.</param>
65+
/// <returns>true if the store contains an element with the specified key; otherwise, false.</returns>
66+
public bool ContainsKey(TKey key) => Storage.ContainsKey(key);
67+
68+
/// <summary>
69+
/// Gets the number of key/value pairs contained in the <see cref="ImmutableTypedValueStore{TKey}" />.
70+
/// </summary>
71+
/// <remarks>
72+
/// This property provides the total count of elements present in the underlying immutable dictionary storage.
73+
/// </remarks>
74+
public int Count => Storage.Count;
75+
/// <summary>
76+
/// Returns an enumerator that iterates through the collection of key-value pairs.
77+
/// </summary>
78+
/// <returns>
79+
/// An <see cref="IEnumerator" /> that can be used to iterate through the collection.
80+
/// </returns>
81+
public IEnumerator GetEnumerator() => Storage.GetEnumerator();
82+
}

0 commit comments

Comments
 (0)