Skip to content

Instantly share code, notes, and snippets.

@AlbertoMonteiro
Created October 16, 2017 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlbertoMonteiro/354d8280538a083f08de75d376d5b4ff to your computer and use it in GitHub Desktop.
Save AlbertoMonteiro/354d8280538a083f08de75d376d5b4ff to your computer and use it in GitHub Desktop.
Descobrir propriedades string na arvore de um type
using System;
namespace ConsoleApp2
{
class Program
{
private static readonly Type StringType = typeof(string);
static void Main(string[] args)
{
ObterPropriedadesString(typeof(Pessoa));
}
public static void ObterPropriedadesString(Type tipo)
{
foreach (var propertyInfo in tipo.GetProperties())
{
if (propertyInfo.PropertyType == StringType)
Console.WriteLine($"Encontrado propriedade string de nome {propertyInfo.Name} em {tipo.FullName} ");
else if (propertyInfo.PropertyType.IsClass)
ObterPropriedadesString(propertyInfo.PropertyType);
}
}
}
class Pessoa
{
public string Nome { get; set; }
public short Idade { get; set; }
public Carro Carro { get; set; }
}
class Carro
{
public string Modelo { get; set; }
public Fabricante Fabricante { get; set; }
}
class Fabricante
{
public string Nome { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment