Skip to content

Instantly share code, notes, and snippets.

@19WAS85
Created May 13, 2009 17:43
Show Gist options
  • Save 19WAS85/111152 to your computer and use it in GitHub Desktop.
Save 19WAS85/111152 to your computer and use it in GitHub Desktop.
public static object GetPropertyValue(this object obj, string propertyName)
{
try
{
return obj.GetType().GetProperty(propertyName).GetValue(obj, null);
}
catch
{
return null;
}
}
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();
}
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