Skip to content

Commit 0f8f4fe

Browse files
authored
Improves the Slots Equality check improvement for value types
* Adds .editorconfig * Adds TestStructItem * Adds metadata to TheChest.Core package * Adds BaseTest to the unit tests tests * Adds DIContainer to unit tests * Adds TypeConditionAttribute to unit tests * Adds DIContainer to unit tests * Adds Slot constructor unit tests * Implements unit tests for TestStructItem to Slot * Improves in docs XML * Changes unit tests libraries to stable versions * Changes in slot namespaces * Changes the project to accepts nullable references * Changes in .editorconfig indetation configs * Changes in Slots Structure to hold content as an object * Changes in class_diagram to match new class structure * Fixes typo in CHANGELOG.md
1 parent 1a83b5a commit 0f8f4fe

File tree

88 files changed

+1528
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1528
-608
lines changed

.editorconfig

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[*.cs]
2+
#### Naming styles ####
3+
4+
# Naming rules
5+
6+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
7+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
8+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
9+
10+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
11+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
12+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
13+
14+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
15+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
16+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
17+
18+
# Symbol specifications
19+
20+
dotnet_naming_symbols.interface.applicable_kinds = interface
21+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
22+
dotnet_naming_symbols.interface.required_modifiers =
23+
24+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
25+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
26+
dotnet_naming_symbols.types.required_modifiers =
27+
28+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
29+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
30+
dotnet_naming_symbols.non_field_members.required_modifiers =
31+
32+
# Naming styles
33+
34+
dotnet_naming_style.begins_with_i.required_prefix = I
35+
dotnet_naming_style.begins_with_i.required_suffix =
36+
dotnet_naming_style.begins_with_i.word_separator =
37+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
38+
39+
dotnet_naming_style.pascal_case.required_prefix =
40+
dotnet_naming_style.pascal_case.required_suffix =
41+
dotnet_naming_style.pascal_case.word_separator =
42+
dotnet_naming_style.pascal_case.capitalization = pascal_case
43+
44+
dotnet_naming_style.pascal_case.required_prefix =
45+
dotnet_naming_style.pascal_case.required_suffix =
46+
dotnet_naming_style.pascal_case.word_separator =
47+
dotnet_naming_style.pascal_case.capitalization = pascal_case
48+
csharp_space_around_binary_operators = before_and_after
49+
csharp_style_expression_bodied_methods = false:silent
50+
csharp_style_expression_bodied_constructors = false:silent
51+
csharp_style_expression_bodied_operators = false:silent
52+
csharp_style_expression_bodied_properties = true:silent
53+
csharp_style_expression_bodied_indexers = true:silent
54+
csharp_style_expression_bodied_accessors = true:silent
55+
csharp_style_expression_bodied_lambdas = true:silent
56+
csharp_style_expression_bodied_local_functions = false:silent
57+
csharp_using_directive_placement = outside_namespace:silent
58+
csharp_style_prefer_switch_expression = true:suggestion
59+
csharp_style_prefer_pattern_matching = true:silent
60+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
61+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
62+
csharp_style_prefer_not_pattern = true:suggestion
63+
csharp_style_prefer_extended_property_pattern = true:suggestion
64+
csharp_prefer_static_local_function = true:suggestion
65+
csharp_prefer_static_anonymous_function = true:suggestion
66+
csharp_style_prefer_readonly_struct_member = true:suggestion
67+
csharp_style_prefer_readonly_struct = true:suggestion
68+
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
69+
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
70+
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
71+
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
72+
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
73+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
74+
csharp_indent_labels = one_less_than_current
75+
76+
[*.{cs,vb}]
77+
end_of_line = crlf
78+
dotnet_style_qualification_for_field = false:silent
79+
dotnet_style_qualification_for_property = false:silent
80+
dotnet_style_qualification_for_method = false:silent
81+
dotnet_style_qualification_for_event = false:silent
82+
dotnet_style_readonly_field = true:suggestion
83+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
84+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
85+
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
86+
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
87+
dotnet_style_coalesce_expression = true:suggestion
88+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
89+
dotnet_style_null_propagation = true:suggestion
90+
dotnet_style_prefer_auto_properties = true:silent
91+
tab_width = 4
92+
indent_size = 4

CHANGELOG.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1+
# v0.15.0
2+
3+
## What's Added
4+
* `.editorconfig` with code style rules
5+
* `Nullable` enabled for the project
6+
* Slots now have a private field named `content`
7+
* It can stores the content from constructor and be `nullable`
8+
* Attribute for unit tests (`[IgnoreIfReferenceType]` and `[IgnoreIfValueType]`)
9+
* Slots now have static Valitation methods to be used in constructors
10+
* `StackSlot<T>`
11+
* `ValidateContent(T[] items, int maxAmount)` - Validates that `items` array is not null or empty and does not exceed `maxAmount`.
12+
* `ValidateAmount(int amount, int maxAmount)` - Validates that `amount` is within the allowed range from zero to `maxAmount`.
13+
* `LazyStackSlot<T>`
14+
* `ValidateAmount(int amount, int maxAmount)` - Validates that `amount` is within the allowed range from zero to `maxAmount`.
15+
* `MaxAmount` and `Amount` now calls the static Validation methods in its constructors
16+
## What's Changed
17+
* Slots now supports reference and value types.
18+
## Known issues
19+
* Unit test project is a mess...
20+
## What's Next
21+
* [#127](https://github.com/The-Chest/TheChest.Core/issues/127) - More wayw to instantiate the Container classes
22+
* [#122](https://github.com/The-Chest/TheChest.Core/issues/122) - XML docs descriptions of the interfaces and some properties are not describing improvements
23+
24+
**Full Changelog**: https://github.com/The-Chest/TheChest.Core/compare/v0.14.0...v0.15.0
25+
126
# v0.14.0
227

328
## What's Removed
4-
* Removed `this[index]` from `IContainer`,`IStackContainer` e `ILazyStackContainer`
5-
* Removed `this[index]` from `Container`,`StackContainer` e `LazyStackContainer`
29+
* Removed `this[index]` from `IContainer`,`IStackContainer` and `ILazyStackContainer`
30+
* Removed `this[index]` from `Container`,`StackContainer` and `LazyStackContainer`
631

732
## What's next
833
* Aiming to release `TheChest.Core` v1.0.0 on the next release

TheChest.Core.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{DBF05821-E
1616
docs\class_diagram.md = docs\class_diagram.md
1717
EndProjectSection
1818
EndProject
19+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "configs", "configs", "{380A7511-A354-6D7A-0CC0-8FA1F1BA7B6C}"
20+
ProjectSection(SolutionItems) = preProject
21+
.editorconfig = .editorconfig
22+
.config\dotnet-tools.json = .config\dotnet-tools.json
23+
EndProjectSection
24+
EndProject
1925
Global
2026
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2127
Debug|Any CPU = Debug|Any CPU

docs/class_diagram.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ direction BT
4444
}
4545
namespace TheChest.Core.Slots {
4646
class Slot~T~ {
47-
-T content
47+
-object? content
48+
+T Content
4849
+bool IsEmpty
4950
+bool IsFull
5051
+bool Contains(T item)
@@ -102,8 +103,12 @@ direction BT
102103
+bool Contains(T item)
103104
+bool Contains(T item, int amount)
104105
}
106+
}
107+
108+
namespace TheChest.Core.Slots {
105109
class StackSlot~T~{
106-
-T content
110+
-object?[] content
111+
+T[] Content
107112
-int amount
108113
+int Amount
109114
+int MaxAmount
@@ -163,6 +168,19 @@ direction BT
163168
}
164169
}
165170
171+
namespace TheChest.Core.Slots {
172+
class LazyStackSlot~T~{
173+
-object? content
174+
+T Content
175+
-int amount
176+
+int Amount
177+
+int MaxAmount
178+
-int maxAmount
179+
+bool IsEmpty
180+
+bool IsFull
181+
}
182+
}
183+
166184
<<interface>> ILazyStackContainer
167185
<<interface>> ILazyStackSlot
168186

src/TheChest.Core/Slots/LazyStackSlot.cs

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,31 @@ public class LazyStackSlot<T> : ILazyStackSlot<T>
1212
/// <summary>
1313
/// The content inside the slot
1414
/// </summary>
15-
protected T content;
15+
private object? content;
1616
/// <summary>
17-
/// The current amount of items inside the slot
17+
/// The content inside the slot
1818
/// </summary>
19-
protected int amount;
19+
public virtual T Content
20+
{
21+
get
22+
{
23+
#pragma warning disable CS8603
24+
if (typeof(T).IsValueType && this.content is null)
25+
return default;
26+
27+
return (T)this.content;
28+
#pragma warning restore CS8603
29+
}
30+
protected set
31+
{
32+
this.content = value;
33+
}
34+
}
35+
2036
/// <summary>
21-
/// The maximum amount of items that this slot can hold
37+
/// The current amount of items inside the slot
2238
/// </summary>
23-
protected int maxAmount;
24-
39+
protected int amount;
2540
/// <inheritdoc/>
2641
public virtual int Amount
2742
{
@@ -31,22 +46,15 @@ public virtual int Amount
3146
}
3247
protected set
3348
{
34-
if (value < 0)
35-
throw new ArgumentOutOfRangeException(
36-
nameof(value),
37-
"The amount property cannot be smaller than zero"
38-
);
39-
40-
if (value > this.maxAmount)
41-
throw new ArgumentOutOfRangeException(
42-
nameof(value),
43-
"The item amount cannot be bigger than max amount"
44-
45-
);
46-
49+
ValidateAmount(value, this.maxAmount);
4750
this.amount = value;
4851
}
4952
}
53+
54+
/// <summary>
55+
/// The maximum amount of items that this slot can hold
56+
/// </summary>
57+
protected int maxAmount;
5058
/// <inheritdoc/>
5159
public virtual int MaxAmount
5260
{
@@ -56,43 +64,70 @@ public virtual int MaxAmount
5664
}
5765
protected set
5866
{
59-
if (value < 0)
60-
throw new ArgumentOutOfRangeException(
61-
nameof(value),
62-
"The max amount property cannot be smaller than zero"
63-
);
64-
65-
if (value < this.amount)
66-
throw new ArgumentOutOfRangeException(
67-
nameof(value),
68-
"The item amount cannot be bigger than max amount"
69-
);
70-
67+
ValidateAmount(this.amount, value);
7168
this.maxAmount = value;
7269
}
7370
}
7471

7572
/// <inheritdoc/>
76-
public virtual bool IsFull => this.Amount == this.MaxAmount && !(this.content is null);
73+
public virtual bool IsFull => !this.IsEmpty && this.amount == this.maxAmount;
7774
/// <inheritdoc/>
78-
public virtual bool IsEmpty => this.Amount == 0 || this.content is null;
75+
public virtual bool IsEmpty => this.amount == 0 || this.content is null;
7976

77+
/// <summary>
78+
/// Initializes a new instance of the <see cref="LazyStackSlot{T}"/> class with default values.
79+
/// </summary>
80+
/// <remarks>
81+
/// The slot is initialized with no content, an amount of zero, and a maximum amount of one.
82+
/// </remarks>
83+
public LazyStackSlot()
84+
{
85+
this.content = null;
86+
this.amount = 0;
87+
this.maxAmount = 1;
88+
}
8089
/// <summary>
8190
/// Creates a basic Stack Slot with an amount and max amount
8291
/// </summary>
8392
/// <param name="currentItem">The current item to be added</param>
8493
/// <param name="amount">The amount of <paramref name="currentItem"/> to be added</param>
8594
/// <param name="maxAmount">The maximum permited amount of <paramref name="currentItem"/> to be added</param>
8695
/// <exception cref="ArgumentOutOfRangeException"></exception>
87-
public LazyStackSlot(T currentItem = default!, int amount = 1, int maxAmount = 1)
96+
public LazyStackSlot(T currentItem, int amount = 1, int maxAmount = 1)
8897
{
98+
ValidateAmount(amount, maxAmount);
99+
89100
this.content = currentItem;
90-
this.MaxAmount = maxAmount;
101+
this.amount = this.content is null ? 0 : amount;
102+
this.maxAmount = maxAmount;
103+
}
91104

92-
if (currentItem is null)
93-
this.Amount = 0;
94-
else
95-
this.Amount = amount;
105+
/// <summary>
106+
/// Validates that <paramref name="amount"/> is within the allowed range from zero to <paramref name="maxAmount"/>.
107+
/// </summary>
108+
/// <param name="amount">The amount to be validated.</param>
109+
/// <param name="maxAmount">The maximum allowed amount.</param>
110+
/// <exception cref="ArgumentOutOfRangeException">
111+
/// When <paramref name="amount"/> is less than zero, greater than <paramref name="maxAmount"/>,
112+
/// or <paramref name="maxAmount"/> is less than zero.
113+
/// </exception>
114+
protected static void ValidateAmount(int amount, int maxAmount)
115+
{
116+
if (amount < 0)
117+
throw new ArgumentOutOfRangeException(
118+
nameof(amount),
119+
"The amount property cannot be smaller than zero"
120+
);
121+
if (maxAmount < 0)
122+
throw new ArgumentOutOfRangeException(
123+
nameof(maxAmount),
124+
"The max amount property cannot be smaller than zero"
125+
);
126+
if (amount > maxAmount)
127+
throw new ArgumentOutOfRangeException(
128+
nameof(amount),
129+
"The item amount cannot be bigger than max amount"
130+
);
96131
}
97132

98133
/// <inheritdoc/>
@@ -107,7 +142,6 @@ public virtual bool Contains(T item)
107142

108143
return item.Equals(this.content);
109144
}
110-
111145
/// <inheritdoc/>
112146
/// <exception cref="ArgumentNullException">When <paramref name="item"/> is null</exception>
113147
public virtual bool Contains(T item, int amount)

0 commit comments

Comments
 (0)