Skip to content

Commit

Permalink
Fixed small issue with enum serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonseydel committed Jun 13, 2016
1 parent 7f94ca3 commit c1740fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
24 changes: 14 additions & 10 deletions MailChimp.Net/Core/StringEnumDescriptionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,22 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
if (value == null)
{
writer.WriteNull();
return;
}
else
{
var type = value.GetType();
var name = Enum.GetName(type, value);
var description = type.GetField(name) // I prefer to get attributes this way
.GetCustomAttributes(false)
.OfType<DescriptionAttribute>()
.Select(x => x.Description)
.SingleOrDefault();
writer.WriteValue(description ?? name);

var type = value.GetType();
var name = Enum.GetName(type, value);
if (string.IsNullOrWhiteSpace(name)) {
writer.WriteNull();
return;
}

var description = type.GetField(name) // I prefer to get attributes this way
.GetCustomAttributes(false)
.OfType<DescriptionAttribute>()
.Select(x => x.Description)
.SingleOrDefault();
writer.WriteValue(description ?? name);
}
}
}
2 changes: 1 addition & 1 deletion MailChimp.Net/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.1")]
[assembly: AssemblyVersion("1.5.2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
9 changes: 9 additions & 0 deletions MailChimp.Net/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Example:
IMailChimpManager manager = new MailChimpManager(apiKey); //if you have it in code
IMailChimpManager manager = new MailChimpManager(); //if you have it in config

Get Conversations -
var conversations = await this._mailChimpManager.Conversations.GetAllAsync();

Project is hosted on GitHub:
https://github.com/brandonseydel/MailChimp.Net

0 comments on commit c1740fa

Please sign in to comment.