実際にはリストであるオブジェクトがあります。要素の型が何か文字列がありますが、オブジェクトをリストにキャストする方法がわかりませんか? ここに私の問題を描いたコードがあります。
class Data
{
public int ID { get; set; }
public List<double> Values { get; set; }
}
static void Main(string[] args)
{
Data d = new Data() { ID = 69, Values = new List<double>() };
d.Values.Add(1.0);
d.Values.Add(2.0);
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(Data));
var propInfo = typeof(Data).GetProperties();
foreach (var p in propInfo)
{
var Value = p.GetValue(d, null);
var Type = p.PropertyType;
if (Type.IsGenericType && Type.GetGenericTypeDefinition() == typeof(List<>))
{
// get the element type of a list
var ElementType = Value.GetType().GetProperty("Item").PropertyType;
// how to cast to List< "ElementType" > ???
}
else
{
types.Add( Type.FullName );
}
}
}