Skip to content

Commit de5f275

Browse files
author
Oren (electricessence)
committed
Prep for update source publish.
1 parent 8e00d3a commit de5f275

9 files changed

Lines changed: 66 additions & 53 deletions

File tree

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[*.cs]
2+
3+
# CA1707: Identifiers should not contain underscores
4+
dotnet_diagnostic.CA1707.severity = silent
5+
6+
# CA1303: Do not pass literals as localized parameters
7+
dotnet_diagnostic.CA1303.severity = silent
8+
9+
# CA1051: Do not declare visible instance fields
10+
dotnet_diagnostic.CA1051.severity = silent
11+
12+
# CA1034: Nested types should not be visible
13+
dotnet_diagnostic.CA1034.severity = silent

.github/workflows/main.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

IChild.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Diagnostics.Contracts;
25

36
namespace Open.Hierarchy
47
{
@@ -19,6 +22,7 @@ public interface IChild<out TParent> : IChild
1922
new TParent? Parent { get; }
2023
}
2124

25+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "Null check properly implemented.")]
2226
public static class ChildExtensions
2327
{
2428
/// <summary>
@@ -31,6 +35,7 @@ public static IEnumerable<TNode> GetAncestors<TNode>(
3135
this TNode node)
3236
where TNode : class, IChild<TNode>
3337
{
38+
if (node is null) throw new ArgumentNullException(nameof(node));
3439
TNode? parent;
3540
while ((parent = node.Parent) != null)
3641
{
@@ -39,6 +44,7 @@ public static IEnumerable<TNode> GetAncestors<TNode>(
3944
}
4045
}
4146

47+
4248
/// <summary>
4349
/// Crawls the ancestor lineage returns the first node with no parent.
4450
/// </summary>
@@ -49,6 +55,7 @@ public static TNode GetRoot<TNode>(
4955
this TNode node)
5056
where TNode : class, IChild<TNode>
5157
{
58+
if (node is null) throw new ArgumentNullException(nameof(node));
5259
TNode? parent;
5360
while ((parent = node.Parent) != null)
5461
{

Node.Factory.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public Node<T> GetNodeWithValue(T value, bool asUnmapped = false)
6262
#endif
6363
public T Recycle(Node<T> node)
6464
{
65-
if (node == null) throw new ArgumentNullException(nameof(node));
65+
if (node is null) throw new ArgumentNullException(nameof(node));
6666
if (node._factory != this)
6767
throw new ArgumentException("The node being provided for recycling does not belong to this factory.", nameof(node));
6868
Contract.EndContractBlock();
@@ -77,7 +77,7 @@ internal T RecycleInternal(Node<T> n)
7777
{
7878
var value = n.Value;
7979
var p = _pool;
80-
if (p == null) n.Teardown();
80+
if (p is null) n.Teardown();
8181
else p.Give(n);
8282
return value;
8383
}
@@ -100,6 +100,7 @@ static void PrepareForPool(Node<T> n)
100100
public Node<T> Map<TRoot>(TRoot root)
101101
where TRoot : T
102102
{
103+
if (root is null) throw new ArgumentNullException(nameof(root));
103104
var current = GetBlankNode();
104105
current.Value = root;
105106

@@ -125,8 +126,11 @@ public Node<T> Map<TRoot>(TRoot root)
125126
/// <param name="container">The container of the root instance.</param>
126127
/// <returns>The full map of the root.</returns>
127128
public Node<T> Map<TRoot>(IHaveRoot<TRoot> container)
128-
where TRoot : T => Map(container.Root);
129-
129+
where TRoot : T
130+
{
131+
if (container is null) throw new ArgumentNullException(nameof(container));
132+
return Map(container.Root);
133+
}
130134
}
131135

132136
}

Node.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ public int IndexOf(Node<T> child)
106106

107107
void AssertOkToJoinFamily(Node<T> child)
108108
{
109-
if (child.Parent == null) return;
109+
if (child.Parent is null) return;
110110
if (child.Parent == this)
111111
throw new InvalidOperationException("Provided node already belongs to this parent.");
112112
throw new InvalidOperationException("Provided node belongs to another parent.");
113113
}
114114

115115
public void Insert(int index, Node<T> child)
116116
{
117-
if (child == null) throw new ArgumentNullException(nameof(child));
117+
if (child is null) throw new ArgumentNullException(nameof(child));
118118
Contract.EndContractBlock();
119119

120120
AssertNotRecycled();
@@ -156,7 +156,7 @@ public Node<T> this[int index]
156156
/// <inheritdoc />
157157
public bool Contains(Node<T> child)
158158
{
159-
if (child == null) throw new ArgumentNullException(nameof(child));
159+
if (child is null) throw new ArgumentNullException(nameof(child));
160160
Contract.EndContractBlock();
161161

162162
return _children.Contains(child);
@@ -165,7 +165,7 @@ public bool Contains(Node<T> child)
165165
/// <inheritdoc />
166166
public bool Remove(Node<T> child)
167167
{
168-
if (child == null) throw new ArgumentNullException(nameof(child));
168+
if (child is null) throw new ArgumentNullException(nameof(child));
169169
Contract.EndContractBlock();
170170

171171
if (!_children.Remove(child)) return false;
@@ -179,7 +179,7 @@ public bool Remove(Node<T> child)
179179
/// <inheritdoc />
180180
public void Add(Node<T> child)
181181
{
182-
if (child == null) throw new ArgumentNullException(nameof(child));
182+
if (child is null) throw new ArgumentNullException(nameof(child));
183183
Contract.EndContractBlock();
184184

185185
AssertNotRecycled();
@@ -240,8 +240,8 @@ public void AddValue(T value, bool asUnmapped = false)
240240
/// <param name="replacement">The node to use as a replacement.</param>
241241
public void Replace(Node<T> node, Node<T> replacement)
242242
{
243-
if (node == null) throw new ArgumentNullException(nameof(node));
244-
if (replacement == null) throw new ArgumentNullException(nameof(replacement));
243+
if (node is null) throw new ArgumentNullException(nameof(node));
244+
if (replacement is null) throw new ArgumentNullException(nameof(replacement));
245245
Contract.EndContractBlock();
246246

247247
if (replacement.Parent != null)

Open.Hierarchy.csproj

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,32 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
5+
<LangVersion>latest</LangVersion>
6+
<Nullable>enable</Nullable>
57
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
68
<Authors>electricessence</Authors>
7-
<Company>electricessence</Company>
8-
<Description>
9-
Interfaces and classes helful in managing tree-like data structures.
10-
11-
Part of the "Open" set of libraries.
12-
</Description>
13-
<Copyright>https://github.com/electricessence/Open.Hierarchy/blob/master/LICENSE</Copyright>
14-
<PackageLicenseUrl></PackageLicenseUrl>
15-
<PackageProjectUrl>https://github.com/electricessence/Open.Hierarchy/</PackageProjectUrl>
16-
<RepositoryUrl>https://github.com/electricessence/Open.Hierarchy/</RepositoryUrl>
9+
<Description>Interfaces and classes helful in managing tree-like data structures.
10+
11+
Part of the "Open" set of libraries.
12+
</Description>
13+
<Copyright>https://github.com/Open-NET-Libraries/Open.Hierarchy/blob/master/LICENSE</Copyright>
14+
<PackageProjectUrl>https://github.com/Open-NET-Libraries/Open.Hierarchy/</PackageProjectUrl>
15+
<RepositoryUrl>https://github.com/Open-NET-Libraries/Open.Hierarchy/</RepositoryUrl>
1716
<RepositoryType>git</RepositoryType>
1817
<PackageTags>dotnet, dotnetcore, cs, tree, node, hierarchy, parent, child, root</PackageTags>
19-
<Version>1.7.2</Version>
18+
<Version>1.7.3</Version>
2019
<PackageReleaseNotes></PackageReleaseNotes>
2120
<PackageLicenseExpression>MIT</PackageLicenseExpression>
22-
<Nullable>enable</Nullable>
23-
2421
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2522
<IncludeSymbols>true</IncludeSymbols>
2623
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
27-
</PropertyGroup>
24+
<PackageIcon>logo.png</PackageIcon>
25+
</PropertyGroup>
2826

2927
<ItemGroup>
3028
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
3129
</ItemGroup>
3230

33-
3431
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
3532
<LangVersion>latest</LangVersion>
3633
</PropertyGroup>
@@ -40,13 +37,27 @@
4037
</PropertyGroup>
4138

4239
<ItemGroup>
40+
<None Remove=".editorconfig" />
4341
<None Remove=".git" />
4442
<None Remove=".gitignore" />
4543
<None Remove="LICENSE" />
44+
<None Remove="Readme.md" />
45+
<None Include="logo.png">
46+
<Pack>True</Pack>
47+
<PackagePath></PackagePath>
48+
</None>
49+
</ItemGroup>
50+
51+
<ItemGroup>
52+
<AdditionalFiles Include=".editorconfig" />
4653
</ItemGroup>
4754

4855
<ItemGroup>
4956
<PackageReference Include="Open.Disposable.ObjectPools" Version="2.4.1" />
57+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
58+
<PrivateAssets>all</PrivateAssets>
59+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
60+
</PackageReference>
5061
</ItemGroup>
5162

5263
</Project>

Readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Open.Hierarchy
22

3-
![.NET Core](https://github.com/Open-NET-Libraries/Open.Hierarchy/workflows/.NET%20Core/badge.svg) [![NuGet](http://img.shields.io/nuget/v/Open.Hierarchy.svg)](https://www.nuget.org/packages/Open.Hierarchy/)
3+
![.NET Core](https://github.com/Open-NET-Libraries/Open.Hierarchy/workflows/.NET%20Core/badge.svg)
4+
[![NuGet](https://img.shields.io/nuget/v/Open.Hierarchy.svg)](https://www.nuget.org/packages/Open.Hierarchy/)
45

56
## `Node<T>`
67

TraversalExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public static IEnumerable<TNode> GetNodesOfType<TNode>(
6767
public static IEnumerable<object> GetDescendants(
6868
this IParent root, TraversalMode traversal = TraversalMode.BreadthFirst)
6969
{
70+
if (root is null) throw new ArgumentNullException(nameof(root));
71+
7072
// Attempt to be more breadth first.
7173
switch (traversal)
7274
{

logo.png

54.6 KB
Loading

0 commit comments

Comments
 (0)