Last active
December 17, 2015 22:48
-
-
Save makomweb/5684156 to your computer and use it in GitHub Desktop.
Gravatar URI fallback extension.
This file contains hidden or 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
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