我有一个泛型类型List<Shift>
,其中
public class Shift
{
[DisplayFormat(DataFormatString = "dd-MMM-yyy '(hours)'")]
public DateTimeOffset Date { get; set; }
[DisplayFormat(DataFormatString = "hh':'mm")]
public TimeSpan TimeWorked { get; set; }
}
我正在尝试使用反射获取具有属性的时间表道具
var props = typeof(List<ShiftDayItem>).GetProperties();
var ShiftProperty = props.Last();
但是ShiftProperty不包含任何属性,因此我无法访问Date或TimeWorked。反射是否没有意识到这些,或者我还有另一种获取这些属性的方法吗?谢谢!
你需要更多代码:
Dim shifttprops= ShiftProperty.PropertyType.GetProperties()
For Each prop in shifttprops
Dim attrs = prop.CustomAttributes
Next
注意使用CustomAttributes
代替Attributes
尽管问题尚不清楚,但您可能正在正确的道路上。但是您可能应该考虑在C#中举一个例子