-
Notifications
You must be signed in to change notification settings - Fork 966
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
Custom enum description attribute property names #277
Merged
MehdiK
merged 9 commits into
Humanizr:master
from
mexx:custom-enum-description-attribute-property-names
May 23, 2014
+78
−4
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
91589c9
retrieve enum case name only once
mexx a5bae33
allow to override enum description attribute property name per type
mexx cd9c8cd
move default property name into configurator
mexx 67018e6
add PR to release notes
mexx 107f1b4
update readme
mexx 83ea7ba
suppress code analysis message for IDisposable in test
mexx 67aa8b0
restore indentation in enum example
mexx 608c041
suppress code analysis message for IDisposable in test
mexx 93a80ea
rework towards locator predicate
mexx 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
31 changes: 31 additions & 0 deletions
31
src/Humanizer.Tests/EnumHumanizeWithCustomDescriptionPropertyNamesTests.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,31 @@ | ||
using System; | ||
using Humanizer.Configuration; | ||
using Xunit; | ||
|
||
namespace Humanizer.Tests | ||
{ | ||
public class EnumHumanizeWithCustomDescriptionPropertyNamesTests : IDisposable | ||
{ | ||
public EnumHumanizeWithCustomDescriptionPropertyNamesTests() | ||
{ | ||
Configurator.EnumDescriptionPropertyNames[typeof (EnumUnderTest)] = "Info"; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Configurator.EnumDescriptionPropertyNames.Remove(typeof (EnumUnderTest)); | ||
} | ||
|
||
[Fact] | ||
public void HonorsCustomPropertyAttribute() | ||
{ | ||
Assert.Equal(EnumTestsResources.MemberWithCustomPropertyAttribute, EnumUnderTest.MemberWithCustomPropertyAttribute.Humanize()); | ||
} | ||
|
||
[Fact] | ||
public void CanHumanizeMembersWithoutDescriptionAttribute() | ||
{ | ||
Assert.Equal(EnumTestsResources.MemberWithoutDescriptionAttributeSentence, EnumUnderTest.MemberWithoutDescriptionAttribute.Humanize()); | ||
} | ||
} | ||
} |
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
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.
I am not sure about the implementation. It feels a bit complex. What if we just created a
DescriptionPropertyLocator
predicate function? Let them keep the logic. This way they can be as flexible as they want!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.
I wanted to provide the possibility to have different property names per enum type.
But as already mentioned it a first attempt, so let discuss further the possibilities.
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.
After a second thought, it would be flexible enough since the
PropertyInfo
has the reference to theDeclaringType
, so even my use case can be implemented with the predicate function.I'll rewrite it now.
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.
I am not sure if that level of granular control is necessary to be honest with you. Also remember
PropertyInfo
is from the attribute not the target enum!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.
Maybe we can just expose
Func<PropertyInfo, bool>
? That way they won't be able to nominate different attributes for different enums but I call YAGNI on it for now.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.
Yes, you're right.
Func<PropertyInfo, bool>
is done.