Revision 3ee5bcdb-043c-4998-9142-9f0a1b1074c6 - Code Review Stack Exchange

It looks rather hacky because I have the feeling there must be someplace down the line where you can more easily determine whether or not the properties are filled in. 

Nevertheless: right now your code will only work for `strings` while it is probably realistic to say that there might be other fields in the future as well (Id, DateOfBirth, etc) which would require a code change. Therefore I would suggest making your code a little less string-specific:

 public bool isEmpty()
 {
 var properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

 foreach (var prop in properties)
 {
 var value = prop.GetValue(this, null);
			
 if (value != default(prop.PropertyType))
 {
 return false;
 }
			
			var stringValue = value as string;
			if(stringValue != null)
			{
				if(stringValue != string.IsNullOrWhiteSpace(value))
				{
					return false;
				}
			}
 }

 return true;
 }

* Using `default` so it words with primitive types (they won't be able to be `0` with this)
* If you do want to be able to be `0`, make them nullable types instead
* [`as` combined with `!= null`][1]
* `IsNullOrWhiteSpace(string)` instead of comparison to empty quotes
* Removed `t` since it was only used once


 [1]: https://stackoverflow.com/questions/496096/casting-vs-using-the-as-keyword-in-the-clr

AltStyle によって変換されたページ (->オリジナル) /