Created
May 13, 2009 17:43
-
-
Save 19WAS85/111152 to your computer and use it in GitHub Desktop.
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
public static object GetPropertyValue(this object obj, string propertyName) | |
{ | |
try | |
{ | |
return obj.GetType().GetProperty(propertyName).GetValue(obj, null); | |
} | |
catch | |
{ | |
return null; | |
} | |
} |
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
public string CriaLink(string titulo, object parametros) | |
{ | |
var para = (string) parametros.GetPropertyValue("Para"); | |
var descricao = (string) parametros.GetPropertyValue("Descricao"); | |
var borda = (int?) parametros.GetPropertyValue("Borda"); | |
var linkBuilder = new StringBuilder(); | |
linkBuilder.Append("<a"); | |
if(!String.IsNullOrEmpty(para)) | |
{ | |
linkBuilder.AppendFormat(" href='{0}'", para); | |
} | |
if(!String.IsNullOrEmpty(descricao)) | |
{ | |
linkBuilder.AppendFormat(" title='{0}'", descricao); | |
} | |
if(borda != null && borda > 0) | |
{ | |
linkBuilder.AppendFormat(" style='border: {0}px solid silver'", borda); | |
} | |
linkBuilder.AppendFormat(">{0}</a>", titulo); | |
return linkBuilder.ToString(); | |
} |
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
CriaLink("Google", new { Para = "http://www.google.com", Descricao = "Clique aqui para acessar o Google.", Borda = 2 }); | |
// <a href='http://www.google.com' title='Clique aqui para acessar o Google.' style='border: 2px solid silver'>Google</a> | |
CriaLink("Globo", new { Para = "http://www.globo.com", Borda = 2 }); | |
// <a href='http://www.globo.com' style='border: 2px solid silver'>Globo</a> | |
CriaLink("Home", new { Para = "/Index.html", Descricao = "Voltar para a página inicial." }); | |
// <a href='/Index.html' title='Voltar para a página inicial.'>Home</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment