Skip to content

Instantly share code, notes, and snippets.

@makomweb
Last active December 17, 2015 22:48
Show Gist options
  • Save makomweb/5684156 to your computer and use it in GitHub Desktop.
Save makomweb/5684156 to your computer and use it in GitHub Desktop.
Gravatar URI fallback extension.
public static class AvatarUriExtensions
{
public static string GetAvatarUri(this User user)
{
return GetAvatarUri(user.AvatarUri, user.Email);
}
/// <summary>
/// Returns the uri or the Gravatar address as a fallback.
/// </summary>
/// <param name="uri">the avatar uri</param>
/// <param name="email">the email address which is used for the fallback.</param>
/// <returns></returns>
private static string GetAvatarUri(string uri, string email)
{
return !string.IsNullOrEmpty(uri) ? uri : new Gravatar.UriBuilder(new HashProvider()).CreateAddress(email);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment