Curious,
You will want to use reflection for this. You can get the Type instance
that represents the type of the class by using the GetType method on Type
(or the object itself, if you have an instance of it), or, if you know the
type at compile-type, you can use the typeof() operator.
Once you have that, you can call GetProperties to get the properties on
the type. The PropertyInfo instances returned will have a PropertyType
property which will return the Type of the property, as well as the Name
property, which returns the name of the property.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Curious" <th****@mail.global.net.mt> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi,
I have a class with properties and each property has specific
datatypes.
Is it possible to extract the datatypes of each property found in a
class?
I would like to extract these datatypes so that I can build a dataset
schema structure at runtime.
Is this possible?
public class MyProperties
{
private int age;
private string name;
public int Age
{
get{...}
set{...}
}
public string Name
{
get{...}
set{...}
}
}
DataTable dt = new DataTable();
foreach(Property p in MyProperties)
{
DataColumn dc = new DataColum(p.Name, p.DataType);
dt.Columns.Add(dc);
}
Can someone help me out
Thanks in Advance