我正在尝试使用反射来 动态设置我想要GetProperty的类型。将有一个值,例如, ,等。这将允许我以后按我想要的顺序将文件添加到列表中。我收到的错误是:OrderByorderByParam"Length""Name""CreationTime"
对象与目标类型不匹配
. 我在这里想念什么?
try
{
PropertyInfo propertyInfo = typeof(FileInfo).GetProperty(orderByParam);
var files = Directory.GetFiles(strPath)
.OrderBy(f => propertyInfo.GetValue(orderByParam, null));
//FileInfo(f).CreationTime))
foreach (string str in files)
{
strFiles.Add(Path.GetFileName(str));
}
}
慕桂英546537
隔江千里
相关分类