How to iterate on all properties of an object in C#?

后端 未结 3 1864
名媛妹妹
名媛妹妹 2021-02-08 16:44

I am new to C#, I want to write a function to iterate over properties of an object and set all null strings to \"\". I have heard that it is possible using something called \"Re

3条回答
  •  借酒劲吻你
    2021-02-08 16:53

    foreach(PropertyInfo pi in myobject.GetType().GetProperties(BindingFlags.Public))
    {
        if (pi.GetValue(myobject)==null)
        {
            // do something
        }
    }
    

提交回复
热议问题