How to check whether all properties of an object are null or empty?

You can do it using Reflection bool IsAnyNullOrEmpty(object myObject) { foreach(PropertyInfo pi in myObject.GetType().GetProperties()) { if(pi.PropertyType == typeof(string)) { string value = (string)pi.GetValue(myObject); if(string.IsNullOrEmpty(value)) { return true; } } } return false; } Matthew Watson suggested an alternative using LINQ: return myObject.GetType().GetProperties() .Where(pi => pi.PropertyType == typeof(string)) .Select(pi => (string)pi.GetValue(myObject)) .Any(value => string.IsNullOrEmpty(value));

‘IsNullOrWhitespace’ in JavaScript?

For a succinct modern cross-browser implementation, just do: function isNullOrWhitespace( input ) { return !input || !input.trim(); } Here’s the jsFiddle. Notes below. The currently accepted answer can be simplified to: function isNullOrWhitespace( input ) { return (typeof input === ‘undefined’ || input == null) || input.replace(/\s/g, ”).length < 1; } And leveraging falsiness, even … Read more

Does C# have IsNullOrEmpty for List/IEnumerable?

nothing baked into the framework, but it’s a pretty straight forward extension method. See here /// <summary> /// Determines whether the collection is null or contains no elements. /// </summary> /// <typeparam name=”T”>The IEnumerable type.</typeparam> /// <param name=”enumerable”>The enumerable, which may be null or empty.</param> /// <returns> /// <c>true</c> if the IEnumerable is null or … Read more

Difference between IsNullOrEmpty and IsNullOrWhiteSpace in C# [duplicate]

Source: MSDN IsNullOrWhiteSpace is a convenience method that is similar to the following code, except that it offers superior performance: return String.IsNullOrEmpty(value) || value.Trim().Length == 0; White-space characters are defined by the Unicode standard. The IsNullOrWhiteSpace method interprets any character that returns a value of true when it is passed to the Char.IsWhiteSpace method as … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)