-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug with Rung comment/text element order. Couple other small cl…
…ean up items. Adding CodeKey.cs as a potential idea to add to LogixCode at some point (maybe).
- Loading branch information
Showing
15 changed files
with
235 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,77 @@ | ||
using System; | ||
|
||
namespace L5Sharp.Core; | ||
|
||
public readonly struct CodeKey : IEquatable<CodeKey> | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="container"></param> | ||
/// <param name="routine"></param> | ||
/// <param name="number"></param> | ||
public CodeKey(string? container, string? routine, uint number) | ||
{ | ||
Container = container ?? string.Empty; | ||
Routine = routine ?? string.Empty; | ||
Number = number; | ||
} | ||
|
||
/// <summary> | ||
/// The containing program or instruction for the line of code within the project. | ||
/// </summary> | ||
/// <value> | ||
/// A <see cref="string"/> representing the name of the containing program or instruction if attached. | ||
/// If not attached to an L5X file, this will be an empty string. | ||
/// </value> | ||
public string Container { get; } | ||
|
||
/// <summary> | ||
/// The name of the routine containing the line of code within the project. | ||
/// </summary> | ||
/// <value> | ||
/// A <see cref="string"/> representing the name of the containing routine if attached. | ||
/// If not attached to an L5X file, this will be an empty string. | ||
/// </value> | ||
public string Routine { get; } | ||
|
||
/// <summary> | ||
/// The number representing the rung, line, or sheet within the routine where the code exists. | ||
/// </summary> | ||
public uint Number { get; } | ||
|
||
|
||
/// <inheritdoc /> | ||
public bool Equals(CodeKey other) => | ||
Container.IsEquivalent(other.Container) && | ||
Routine.IsEquivalent(other.Routine) && | ||
Number == other.Number; | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object? obj) => obj is CodeKey other && Equals(other); | ||
|
||
/// <inheritdoc /> | ||
public override int GetHashCode() => | ||
StringComparer.OrdinalIgnoreCase.GetHashCode(Container) ^ | ||
StringComparer.OrdinalIgnoreCase.GetHashCode(Routine) ^ | ||
Number.GetHashCode(); | ||
|
||
/// <summary> | ||
/// Determines if two objects are equal. | ||
/// </summary> | ||
/// <param name="left">The first object to compare.</param> | ||
/// <param name="right">The second object to compare.</param> | ||
/// <returns><c>true</c> if the objects have the same type and name property; Otherwise, <c>false</c>.</returns> | ||
public static bool operator ==(CodeKey left, CodeKey right) => Equals(left, right); | ||
|
||
/// <summary> | ||
/// Determines if two objects are not equal. | ||
/// </summary> | ||
/// <param name="left">The first object to compare.</param> | ||
/// <param name="right">The second object to compare.</param> | ||
/// <returns><c>true</c> if the objects have the same type and name property; Otherwise, <c>false</c>.</returns> | ||
public static bool operator !=(CodeKey left, CodeKey right) => !Equals(left, right); | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() => $"{Container}/{Routine}/{Number}"; | ||
} |
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
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
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
3 changes: 3 additions & 0 deletions
3
tests/L5Sharp.Tests/Elements/RungTests.New_Default_ShouldBeVerified.verified.xml
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,3 @@ | ||
<Rung Type="N"> | ||
<Text></Text> | ||
</Rung> |
3 changes: 3 additions & 0 deletions
3
tests/L5Sharp.Tests/Elements/RungTests.New_TextOverload_ShouldBeVerified.verified.xml
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,3 @@ | ||
<Rung Type="N"> | ||
<Text>XIC(MyTag)[OTE(SomeOutput)TMR(TimerTag,?,?)];</Text> | ||
</Rung> |
4 changes: 4 additions & 0 deletions
4
tests/L5Sharp.Tests/Elements/RungTests.SetCommentThenText_ShouldBeValid.verified.xml
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,4 @@ | ||
<Rung Type="N"> | ||
<Comment>This is a test comment</Comment> | ||
<Text>AFI;</Text> | ||
</Rung> |
4 changes: 4 additions & 0 deletions
4
tests/L5Sharp.Tests/Elements/RungTests.SetComment_DefaultRung_ShouldBeValid.verified.xml
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,4 @@ | ||
<Rung Type="N"> | ||
<Comment>This is a test comment</Comment> | ||
<Text></Text> | ||
</Rung> |
4 changes: 4 additions & 0 deletions
4
....Tests/Elements/RungTests.SetTextToNullThenCommentThenTextAgainShouldBeValid.verified.xml
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,4 @@ | ||
<Rung Type="N"> | ||
<Comment>This is a test comment</Comment> | ||
<Text>AFI;</Text> | ||
</Rung> |
Oops, something went wrong.