-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using a more reliable way to convert groups to links. Added LinksGroup struct and ILinksGroupListExtensions class. Link struct: * Added Combine method. * Removed AddDependency method.
- Loading branch information
Showing
5 changed files
with
117 additions
and
40 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
Platform.Communication.Protocol.Lino/ILinksGroupListExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
|
||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
|
||
namespace Platform.Communication.Protocol.Lino | ||
{ | ||
public static class ILinksGroupListExtensions | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static List<Link> ToLinksList(this IList<LinksGroup> groups) | ||
{ | ||
var list = new List<Link>(); | ||
for (var i = 0; i < groups.Count; i++) | ||
{ | ||
groups[i].AppendToLinksList(list); | ||
} | ||
return list; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using Platform.Collections; | ||
using Platform.Collections.Lists; | ||
|
||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
|
||
namespace Platform.Communication.Protocol.Lino | ||
{ | ||
public struct LinksGroup : IEquatable<LinksGroup> | ||
{ | ||
public Link Link | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get; | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
set; | ||
} | ||
|
||
public IList<LinksGroup> Groups | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get; | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
set; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public LinksGroup(Link link, IList<LinksGroup> groups) | ||
{ | ||
Link = link; | ||
Groups = groups; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public LinksGroup(Link link) : this(link, null) { } | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static implicit operator List<Link>(LinksGroup value) => value.ToLinksList(); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public List<Link> ToLinksList() | ||
{ | ||
var list = new List<Link>(); | ||
AppendToLinksList(list); | ||
return list; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void AppendToLinksList(List<Link> list) => AppendToLinksList(list, Link, this); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static void AppendToLinksList(List<Link> list, Link dependency, LinksGroup group) | ||
{ | ||
list.Add(dependency); | ||
var groups = group.Groups; | ||
if (!groups.IsNullOrEmpty()) | ||
{ | ||
for (int i = 0; i < groups.Count; i++) | ||
{ | ||
var innerGroup = groups[i]; | ||
AppendToLinksList(list, dependency.Combine(innerGroup.Link), innerGroup); | ||
} | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public override bool Equals(object obj) => obj is LinksGroup linksGroup ? Equals(linksGroup) : false; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public override int GetHashCode() => (Link, Groups.GenerateHashCode()).GetHashCode(); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public bool Equals(LinksGroup other) => Link == other.Link && Groups.EqualTo(other.Groups); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static bool operator ==(LinksGroup left, LinksGroup right) => left.Equals(right); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static bool operator !=(LinksGroup left, LinksGroup right) => !(left == right); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters