-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IPStatus extension method GetLocalizedDescription #32
Merged
davidkallesen
merged 5 commits into
main
from
feature/IPStatus-GetLocalizedDescription-Extensions
Dec 4, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0fed4c8
build: Nuget updates
davidkallesen b830f7b
fix: Suppress CA1859, CA1860 and CA1861
davidkallesen d6919b5
feat: Add IPStatusExtensions with GetLocalizedDescription
davidkallesen 9f5aafe
feat: Add IPStatus resource/translation
davidkallesen d5271aa
docs: Update
davidkallesen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,38 @@ ConnectionStateEventArgs. | |
|
||
|
||
|
||
<br /> | ||
|
||
## IPStatusExtensions | ||
Provides extension methods for the `System.Net.NetworkInformation.IPStatus` enumeration. | ||
><b>Remarks:</b> This static class extends the `System.Net.NetworkInformation.IPStatus` enumeration, allowing for easy retrieval of localized string descriptions for each IP status value. This can be particularly useful for displaying user-friendly status messages in applications that perform network operations and diagnostics. | ||
|
||
>```csharp | ||
>public static class IPStatusExtensions | ||
>``` | ||
|
||
### Static Methods | ||
|
||
#### GetLocalizedDescription | ||
>```csharp | ||
>string GetLocalizedDescription(this IPStatus ipStatus) | ||
>``` | ||
><b>Summary:</b> Retrieves a localized description for a specified `System.Net.NetworkInformation.IPStatus` value. | ||
> | ||
><b>Parameters:</b><br> | ||
> `ipStatus` - The value for which a localized description is needed.<br /> | ||
> | ||
><b>Returns:</b> A localized string representation of the specified `System.Net.NetworkInformation.IPStatus` value. | ||
> | ||
><b>Code example:</b> | ||
>```csharp | ||
>This example shows how to call the method on an instance of the enumeration: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Superfluous whitespace in 2 places There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug in markdown-generator for "see cref", this will be fixed in Atc first. |
||
> | ||
>var status = IPStatus.TimedOut; | ||
>var description = status.GetLocalizedDescription(); | ||
>Console.WriteLine(description); // Outputs the localized description for the IPStatus.TimedOut | ||
>``` | ||
|
||
<br /> | ||
|
||
## LoggingEventIdConstants | ||
|
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
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,63 @@ | ||
// ReSharper disable once CheckNamespace | ||
// ReSharper disable LocalizableElement | ||
namespace Atc.Network; | ||
|
||
/// <summary> | ||
/// Provides extension methods for the <see cref="IPStatus"/> enumeration. | ||
/// </summary> | ||
/// <remarks> | ||
/// This static class extends the <see cref="IPStatus"/> enumeration, | ||
/// allowing for easy retrieval of localized string descriptions for each IP status value. | ||
/// This can be particularly useful for displaying user-friendly status messages in applications | ||
/// that perform network operations and diagnostics. | ||
/// </remarks> | ||
public static class IPStatusExtensions | ||
{ | ||
/// <summary> | ||
/// Retrieves a localized description for a specified <see cref="IPStatus"/> value. | ||
/// </summary> | ||
/// <param name="ipStatus">The <see cref="IPStatus"/> value for which a localized description is needed.</param> | ||
/// <returns> | ||
/// A localized string representation of the specified <see cref="IPStatus"/> value. | ||
/// </returns> | ||
/// <exception cref="SwitchCaseDefaultException"> | ||
/// Thrown when the provided <paramref name="ipStatus"/> does not match any of the known cases. | ||
/// </exception> | ||
/// <example> | ||
/// This example shows how to call the <see cref="GetLocalizedDescription"/> method on an instance of the <see cref="IPStatus"/> enumeration: | ||
/// <code> | ||
/// var status = IPStatus.TimedOut; | ||
/// var description = status.GetLocalizedDescription(); | ||
/// Console.WriteLine(description); // Outputs the localized description for the IPStatus.TimedOut | ||
/// </code> | ||
/// </example> | ||
public static string GetLocalizedDescription( | ||
this IPStatus ipStatus) | ||
=> ipStatus switch | ||
{ | ||
IPStatus.Unknown => EnumResources.IPStatusUnknown, | ||
IPStatus.Success => EnumResources.IPStatusSuccess, | ||
IPStatus.DestinationNetworkUnreachable => EnumResources.IPStatusDestinationNetworkUnreachable, | ||
IPStatus.DestinationHostUnreachable => EnumResources.IPStatusDestinationHostUnreachable, | ||
IPStatus.DestinationProhibited => EnumResources.IPStatusDestinationProhibited, | ||
IPStatus.DestinationPortUnreachable => EnumResources.IPStatusDestinationPortUnreachable, | ||
IPStatus.NoResources => EnumResources.IPStatusNoResources, | ||
IPStatus.BadOption => EnumResources.IPStatusBadOption, | ||
IPStatus.HardwareError => EnumResources.IPStatusHardwareError, | ||
IPStatus.PacketTooBig => EnumResources.IPStatusPacketTooBig, | ||
IPStatus.TimedOut => EnumResources.IPStatusTimedOut, | ||
IPStatus.BadRoute => EnumResources.IPStatusBadRoute, | ||
IPStatus.TtlExpired => EnumResources.IPStatusTtlExpired, | ||
IPStatus.TtlReassemblyTimeExceeded => EnumResources.IPStatusTtlReassemblyTimeExceeded, | ||
IPStatus.ParameterProblem => EnumResources.IPStatusParameterProblem, | ||
IPStatus.SourceQuench => EnumResources.IPStatusSourceQuench, | ||
IPStatus.BadDestination => EnumResources.IPStatusBadDestination, | ||
IPStatus.DestinationUnreachable => EnumResources.IPStatusDestinationUnreachable, | ||
IPStatus.TimeExceeded => EnumResources.IPStatusTimeExceeded, | ||
IPStatus.BadHeader => EnumResources.IPStatusBadHeader, | ||
IPStatus.UnrecognizedNextHeader => EnumResources.IPStatusUnrecognizedNextHeader, | ||
IPStatus.IcmpError => EnumResources.IPStatusIcmpError, | ||
IPStatus.DestinationScopeMismatch => EnumResources.IPStatusDestinationScopeMismatch, | ||
_ => throw new SwitchCaseDefaultException(ipStatus), | ||
}; | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superfluous whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug in markdown-generator for "see cref", this will be fixed in Atc first.