Skip to content

Commit 69d78cb

Browse files
committed
Fix: Some code cleanup
1 parent dddc287 commit 69d78cb

File tree

18 files changed

+436
-430
lines changed

18 files changed

+436
-430
lines changed

.editorconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ dotnet_naming_symbols.private_instance_fields_symbols.resharper_applicable_kinds
7171
dotnet_naming_symbols.private_instance_fields_symbols.resharper_required_modifiers = instance
7272
dotnet_naming_symbols.private_instance_fields_symbols_1.applicable_accessibilities = private
7373
dotnet_naming_symbols.private_instance_fields_symbols_1.applicable_kinds = field
74-
dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_applicable_kinds = field,readonly_field
74+
dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_applicable_kinds = field, readonly_field
7575
dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_required_modifiers = instance
7676
dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private
7777
dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field
@@ -84,11 +84,11 @@ dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = reado
8484
dotnet_naming_symbols.private_static_readonly_symbols.resharper_applicable_kinds = readonly_field
8585
dotnet_naming_symbols.private_static_readonly_symbols.resharper_required_modifiers = static
8686
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = *
87-
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
87+
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
8888
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field
8989
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance
9090
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_accessibilities = *
91-
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds =
91+
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds =
9292
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_applicable_kinds = unity_serialised_field
9393
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_required_modifiers = instance
9494
dotnet_sort_system_directives_first = false
@@ -143,7 +143,7 @@ resharper_formatter_tags_enabled = true
143143
resharper_indent_preprocessor_if = usual_indent
144144
resharper_indent_preprocessor_other = do_not_change
145145
resharper_indent_raw_literal_string = indent
146-
resharper_instance_members_qualify_declared_in =
146+
resharper_instance_members_qualify_declared_in =
147147
resharper_keep_existing_attribute_arrangement = true
148148
resharper_keep_existing_declaration_block_arrangement = true
149149
resharper_keep_existing_embedded_block_arrangement = true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# CodeOfChaos.Types
2+
23
A collection of types and classes widely used throughout the CodeOfChaos project

src/CodeOfChaos.Types.TypedValueStore/CodeOfChaos.Types.TypedValueStore.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
27-
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false" />
28-
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
26+
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false"/>
27+
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false"/>
28+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false"/>
2929
</ItemGroup>
3030

3131
</Project>

src/CodeOfChaos.Types.TypedValueStore/FrozenTypedValueStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public bool TryGetValue<T>(TKey key, [NotNullWhen(true)] out T? value) where T :
7474
/// <value>
7575
/// The total count of elements that exist within the storage of the FrozenTypedValueStore instance.
7676
/// </value>
77-
public int Count => Storage.Count;
77+
public int Count => Storage.Count;
7878

7979
/// <summary>
8080
/// Returns an enumerator that iterates through the frozen dictionary of key-value pairs contained in this store.

src/CodeOfChaos.Types.TypedValueStore/TypedValueStore.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace CodeOfChaos.Types;
1111
// ---------------------------------------------------------------------------------------------------------------------
1212
/// <summary>
1313
/// The TypedValueStore class provides a key-value storage system where the key can be of any string.
14-
/// Is a Helper class of <see cref="TypedValueStore{TKey}"/> already predefined as a string based key storage.
14+
/// Is a Helper class of <see cref="TypedValueStore{TKey}" /> already predefined as a string based key storage.
1515
/// </summary>
1616
public class TypedValueStore : TypedValueStore<string>;
1717

@@ -30,8 +30,7 @@ public class TypedValueStore<TKey> :
3030
IEnumerable<KeyValuePair<TKey, IValueContainer>>,
3131
IEquatable<ImmutableTypedValueStore<TKey>>,
3232
IEquatable<FrozenTypedValueStore<TKey>>
33-
where TKey : notnull
34-
{
33+
where TKey : notnull {
3534
/// <summary>
3635
/// A thread-safe collection that stores key-value pairs where the key is of type <typeparamref name="TKey" /> and the
3736
/// value

src/CodeOfChaos.Types.TypedValueStore/ValueContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public bool TryGetAsValue<T1>([NotNullWhen(true)] out T1? output) where T1 : not
1717
output = default;
1818
return false;
1919
}
20-
20+
2121
public Type GetTypeOfValue() => typeof(T);
2222
}

src/CodeOfChaos.Types/AsynLazy.cs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,45 @@ namespace System;
88
// ---------------------------------------------------------------------------------------------------------------------
99
public class AsyncLazy<T>(Func<CancellationToken, Task<T>> valueFactory) : IAsyncDisposable {
1010
private readonly SemaphoreSlim _semaphore = new(1, 1);
11-
private Task<T>? _value;
1211
private bool _disposed;
13-
12+
private Task<T>? _value;
13+
1414
// -----------------------------------------------------------------------------------------------------------------
1515
// Methods
1616
// -----------------------------------------------------------------------------------------------------------------
17+
public async ValueTask DisposeAsync() {
18+
if (_disposed) return;
19+
20+
_disposed = true;
21+
22+
// First do all the regular stuff
23+
_semaphore.Dispose();
24+
GC.SuppressFinalize(this);
25+
26+
// Value might have not been loaded yet, so dispose accordingly
27+
if (_value == null) return;
28+
29+
T data = await _value.ConfigureAwait(false);
30+
switch (data) {
31+
case IAsyncDisposable asyncDisposable:
32+
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
33+
break;
34+
case IDisposable disposable:
35+
disposable.Dispose();
36+
break;
37+
}
38+
39+
_value = null;
40+
}
41+
1742
public async ValueTask<T> GetValueAsync(CancellationToken ct = default) {
1843
ct.ThrowIfCancellationRequested();
19-
20-
21-
if (_value is {} value ) return await value.ConfigureAwait(false);
22-
44+
45+
46+
if (_value is {} value) return await value.ConfigureAwait(false);
47+
2348
await _semaphore.WaitAsync(ct).ConfigureAwait(false);
24-
49+
2550
try {
2651
// Check once more within the semaphore lock
2752
_value ??= valueFactory(ct);
@@ -36,25 +61,4 @@ public async ValueTask<T> GetValueAsync(CancellationToken ct = default) {
3661

3762
return await _value.ConfigureAwait(false);
3863
}
39-
40-
public async ValueTask DisposeAsync() {
41-
if (_disposed) return;
42-
_disposed = true;
43-
44-
// First do all the regular stuff
45-
_semaphore.Dispose();
46-
GC.SuppressFinalize(this);
47-
48-
// Value might have not been loaded yet, so dispose accordingly
49-
if (_value == null) return;
50-
T data = await _value.ConfigureAwait(false);
51-
switch (data) {
52-
case IAsyncDisposable asyncDisposable: await asyncDisposable.DisposeAsync().ConfigureAwait(false);
53-
break;
54-
case IDisposable disposable: disposable.Dispose();
55-
break;
56-
}
57-
58-
_value = null;
59-
}
6064
}

src/CodeOfChaos.Types/CodeOfChaos.Types.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup Label="InternalsVisibleTo">
26-
<InternalsVisibleTo Include="Tests.CodeOfChaos.Types" />
26+
<InternalsVisibleTo Include="Tests.CodeOfChaos.Types"/>
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
31-
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false" />
32-
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
30+
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false"/>
31+
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false"/>
32+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false"/>
3333
</ItemGroup>
3434

3535
<ItemGroup>
36-
<PackageReference Include="AterraEngine.Unions" Version="2.5.0" />
36+
<PackageReference Include="AterraEngine.Unions" Version="2.5.0"/>
3737
<PackageReference Include="AterraEngine.Unions.Generators" Version="2.5.0">
3838
<PrivateAssets>all</PrivateAssets>
3939
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4040
</PackageReference>
41-
<PackageReference Include="CodeOfChaos.Extensions" Version="0.22.0" />
41+
<PackageReference Include="CodeOfChaos.Extensions" Version="0.22.0"/>
4242
</ItemGroup>
4343

4444
<ItemGroup>
45-
<ProjectReference Include="..\CodeOfChaos.Types.TypedValueStore\CodeOfChaos.Types.TypedValueStore.csproj" />
45+
<ProjectReference Include="..\CodeOfChaos.Types.TypedValueStore\CodeOfChaos.Types.TypedValueStore.csproj"/>
4646
</ItemGroup>
4747

4848
</Project>
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2-
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=data/@EntryIndexedValue">True</s:Boolean>
3-
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=typedvaluestore/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
1+
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib"
2+
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xml:space="preserve">
4+
<s:Boolean
5+
x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=data/@EntryIndexedValue">True</s:Boolean>
6+
<s:Boolean
7+
x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=typedvaluestore/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/CodeOfChaos.Types/Data/RegexLib.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace System.Text.RegularExpressions;
1010
public static partial class CommonRegexLib {
1111

1212
private const RegexOptions DefaultOptions = RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase;
13-
13+
1414
[GeneratedRegex(@"^(\d+)\.(\d+)\.(\d+)(?:\-(\w*))?$", DefaultOptions)]
1515
public static partial Regex SemanticVersion { get; }
1616
}

0 commit comments

Comments
 (0)