-
Notifications
You must be signed in to change notification settings - Fork 862
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 ToString methods for better enum string conversion #3458
Add ToString methods for better enum string conversion #3458
Conversation
Tests invoking |
b6ff509
to
32caa36
Compare
Nice change @paulomorgado |
Thanks, @danielmarbach. Maybe introducing NetEscapades.EnumGenerators: a source generator for enum performance would be a good option to avoid hand-written code. |
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.
The change itself looks good, but these need unit tests
I think this is a good place to put the tests.
I think just testing a few is sufficient, probably no reason to test all of them but I would feel more comfortable knowing we had unit tests.
I wrote a method to get the expected hash of the original type
public static class HashingUtils
{
private static SHA256 SHA256 = SHA256.Create();
public static string GetHash(Type type)
{
return BitConverter.ToString(SHA256.ComputeHash(Encoding.Default.GetBytes(type.ToString()))).Replace("-","");
}
}
which you could use to get the expected hash and then pass that in to AssertEnumUnchanged. You may have to tweak it a little
Done, @peterrsongg! |
Added private ToString methods for various comparison enums in ConditionFactory.cs to improve readability and maintainability. Updated NewCondition methods to use these new ToString methods for consistent string representation. Also, optimized boolean conversion to string using a ternary operator.
32caa36
to
6ad2549
Compare
Updated PolicyTests.cs to include additional namespaces and added new test methods to verify the integrity of various enums by comparing their hashes to expected values. Introduced a new configuration file, AWSSDK.NetFramework.lutconfig, to specify build and test settings, including enabling parallel builds and setting a test case timeout.
6ad2549
to
e83ff12
Compare
Description
ToString
methods for various comparisonenum
s inConditionFactory.cs
to improve readability and maintainability.NewCondition
methods to use these newToString
methods for consistent string representation.boolean
conversion tostring
using a ternary operator.Motivation and Context
The result of invoking
ToString
on anenum
is cached in a limited space and there's no guarantee that the value will be cached for the same value in consecutive invocations.Having code that returns compile-time generated static
string
s will guarantee that thatstring
is always available and easy to access.Invoking
ToString
inbool
will return thestring
literals"True"
or"False"
, depending on its value. However, invokingToLowerInvariant()
on thoseString
s will incur in the generation/allocation of a newstring
every time.Testing
Screenshots (if appropriate)
Types of changes
Checklist
License