Title, this instance takes into account the many properties of the object (regardless of whether this object design is reasonable), when you want to verify that many objects are empty, if else is not considered, and is expected to be implemented with the simplest code, as follows:
Reference: https://codereview.stackexchange.com/questions/70341/check-if-any-of-class-properties-is-not-null-empty-was-assigned
Code:
Objectproperties op =Newobjectproperties (); Op.name="Test"; Op.age= the; StringBuilder SB=NewStringBuilder (); Propertyinfo[] Properties=op. GetType (). GetProperties (); foreach(PropertyInfo Piinchproperties) { if(pi.) GetValue (OP,NULL) !=""&& Pi. GetValue (OP,NULL) !=NULL) {sb. Append (string. Format ("Name: {0} | Value: {1}", Pi. Name, Pi. GetValue (OP,NULL) ) ); }} Console.WriteLine (sb.) ToString ()); Console.ReadLine (); }
Code logic is simple, console application implementation, key code PI. GetValue (OP, null), has run through, to achieve expectations, such as errors, please correct me.
. NET determines whether all properties of an object are empty