mercredi 22 avril 2020

How to get all child properties name from EDM model/Class

Here is the class

    public class AmountData
        {
            public int Id{ get; set; }
            public decimal Amount { get; set; }
            public SentAmount SentAmount{ get; set; }
        }

    public class SentAmount
      {
        public decimal SentAmount { get; set; }
      }

    public class CreditAmount
    {
        public int Id { get; set; }

        public string Timestamp { get; set; }

        public DateTime ReceivedTime { get; set; };

        public byte[] RowVersion { get; set; }

        public bool IsActive { get; set; }

        public AmountData Credit { get; set; }

        public AmountData Debit { get; set; }

        public DateTime CreatedDate { get; set; }

        }

I want all the properties name, type from CreditAmount, AmountData, SentAmount both but I can only use parent class (CreditAmount) for this.

I have tried this using recurisive method but fails

private List<Type> allTypes = new List<Type>();
public void GetProperties(Type type)
        {
            foreach (var p in type.GetProperties())
            {
                allTypes.Add(p.PropertyType);

                foreach(var q in p.PropertyType.GetProperties())
                {
                    GetProperties(q.PropertyType);
                }
            }
        }




Aucun commentaire:

Enregistrer un commentaire