dimanche 29 novembre 2020

c# Reflection, how to get generic type class properties

I have a Generic type List<Shift> where

public class Shift
{
    [DisplayFormat(DataFormatString = "dd-MMM-yyy '(hours)'")]
    public DateTimeOffset Date { get; set; }

    [DisplayFormat(DataFormatString = "hh':'mm")]
    public TimeSpan TimeWorked { get; set; }
}

I'm trying to get schedule props with attributes using reflection

var props = typeof(List<ShiftDayItem>).GetProperties();
var ShiftProperty = props.Last();

But ShiftProperty contains no attributes, so I can't access Date or TimeWorked. Is reflection not aware of these or is there another way for me to get those properties? Thanks!





Aucun commentaire:

Enregistrer un commentaire