In your case I would solve it this way:
This line clsEntidad.getype().getproperty(unaPropiedad);
should replace it with:
var prop = typeof(clsEntidad).GetProperty(unaPropiedad);
You are using the enumerated TypeCode to identify them in the switch correctly only that you assign a value int
to a variable of type Type
in the line: Type tipo = Type.GetTypeCode(prop);
Assuming a class:
public class clsEntidad
{
public int Propiead1 { get; set; }
public decimal Propiedad2 { get; set; }
}
the code would look like this:
string[] listColumnNames = new string[] { "Propiead1", "Propiedad2" };
foreach (string unaPropiedad in listColumnNames)
{
var prop = typeof(clsEntidad).GetProperty(unaPropiedad);
TypeCode tipo = Type.GetTypeCode(prop.PropertyType);
switch (tipo)
{
case TypeCode.Int32:
Console.WriteLine("Propiedad del Tipo: {0}",tipo);
break;
case TypeCode.Decimal:
Console.WriteLine("Propiedad del Tipo: {0} ",tipo);
break;
default:
break;
}
}
Console.ReadKey();
To get the properties of a class and its types you can do it this way (it's a console project for a matter of speed but I hope it works for you):
class Program
{
public int MyProperty1 { get; set; }
public short MyProperty2 { get; set; }
public decimal MyProperty3 { get; set; }
static void Main(string[] args)
{
foreach (var t in typeof(Program).GetProperties())
{
Console.WriteLine("{0} ", t.PropertyType.FullName);
Console.WriteLine();
}
Console.ReadKey();
}
}
and the output would be:
System.Int32
System.Int16
System.Decimal