C#: how to return a list of the names of all properties of an object?

前端 未结 4 477
太阳男子
太阳男子 2021-01-29 00:48

I have a class:

 public class foo
{
    public IEnumerable stst_soldToALTKN { get; set; }
    public int sId { get; set; }        
    public strin         


        
4条回答
  •  温柔的废话
    2021-01-29 01:13

    You can use this:

    public IEnumerable GetAllPropertyNames(object o)
    {
        foreach (PropertyInfo propInfo in o.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
        yield return propInfo.Name;
    }
    

提交回复
热议问题