IsNotBlank() public static méthode

Checks if a String is not empty (""), not null and not whitespace only.
 StringUtil.IsNotBlank(null)      = false StringUtil.IsNotBlank("")        = false StringUtil.IsNotBlank(" ")       = false StringUtil.IsNotBlank("bob")     = true StringUtil.IsNotBlank("  bob  ") = true 
public static IsNotBlank ( string val ) : bool
val string /// the String to check, may be null ///
Résultat bool
Exemple #1
0
 /// <summary>
 /// Throws <see cref="ArgumentException" /> if the parameter <paramref name="o"/>
 /// is <code>null</code> or blank.
 /// </summary>
 /// <param name="o">value to test for blank.</param>
 /// <param name="param">name of the parameter to check.</param>
 /// <exception cref="ArgumentException">if <paramref name="o"/> is <code>null</code> or  blank and constructs a
 /// message with the name of the parameter.</exception>
 public static void BlankCheck(String o, String param)
 {
     Debug.Assert(StringUtil.IsNotBlank(param));
     if (StringUtil.IsBlank(o))
     {
         throw new ArgumentException(String.Format(BLANK_FORMAT, param));
     }
 }
Exemple #2
0
 /// <summary>
 /// Throws <see cref="ArgumentNullException" /> if the parameter <paramref name="o"/>
 /// is <code>null</code>.
 /// </summary>
 /// <param name="o">check if the object is <code>null</code>.</param>
 /// <param name="param">name of the parameter to check for <code>null</code>.</param>
 /// <exception cref="ArgumentNullException">if <paramref name="o"/> is <code>null</code> and constructs a
 /// message with the name of the parameter.</exception>
 public static void NullCheck(Object o, String param)
 {
     Debug.Assert(StringUtil.IsNotBlank(param));
     if (o == null)
     {
         throw new ArgumentNullException(String.Format(NULL_FORMAT, param));
     }
 }
Exemple #3
0
 /// <summary>
 /// Throws <see cref="ArgumentNullException" /> if the parameter <paramref name="o"/>
 /// is <code>null</code>, otherwise returns its value.
 /// </summary>
 /// <typeparam name="T">the type of the parameter to check for <code>null</code>. Must be a reference type.</typeparam>
 /// <param name="o">check if the object is <code>null</code>.</param>
 /// <param name="param">name of the parameter to check for <code>null</code>.</param>
 /// <returns>the value of the parameter <paramref name="o"/>.</returns>
 /// <exception cref="ArgumentNullException">if <paramref name="o"/> is <code>null</code> and constructs a
 /// message with the name of the parameter.</exception>
 public static T NullChecked <T>(T o, String param) where T : class
 {
     // Avoid calling NullCheck() here to reuse code: it deepens the stack trace.
     // We want the exception to be thrown as close to the call site as possible.
     Debug.Assert(StringUtil.IsNotBlank(param));
     if (o == null)
     {
         throw new ArgumentNullException(String.Format(NULL_FORMAT, param));
     }
     return(o);
 }
Exemple #4
0
 /// <summary>
 /// Throws <see cref="ArgumentException" /> if the parameter <paramref name="o"/>
 /// is <code>null</code> or blank, otherwise returns its value.
 /// </summary>
 /// <param name="o">value to test for blank.</param>
 /// <param name="param">name of the parameter to check.</param>
 /// <returns>the value of the parameter <paramref name="o"/>.</returns>
 /// <exception cref="ArgumentException">if <paramref name="o"/> is <code>null</code> or  blank and constructs a
 /// message with the name of the parameter.</exception>
 public static String BlankChecked(String o, String param)
 {
     // Avoid calling BlankCheck() here to reuse code: it deepens the stack trace.
     // We want the exception to be thrown as close to the call site as possible.
     Debug.Assert(StringUtil.IsNotBlank(param));
     if (StringUtil.IsBlank(o))
     {
         throw new ArgumentException(String.Format(BLANK_FORMAT, param));
     }
     return(o);
 }
Exemple #5
0
        /// <summary>
        /// Read the entire stream into a String and return it.
        /// </summary>
        /// <param name="clazz"> </param>
        /// <param name="res"></param>
        /// <returns></returns>
        public static string GetResourceAsString(Type clazz, string res, Encoding charset)
        {
            Debug.Assert(clazz != null && StringUtil.IsNotBlank(res));
            string ret = null;
            Stream ins = GetResourceAsStream(clazz, res);

            if (ins != null)
            {
                using (StreamReader reader = new StreamReader(ins, charset))
                {
                    ret = reader.ReadToEnd();
                }
                QuietClose(ins);
            }
            return(ret);
        }
Exemple #6
0
        /// <summary>
        /// Get the resource as a byte array.
        /// </summary>
        /// <param name="clazz"> </param>
        /// <param name="res">
        /// @return </param>
        public static byte[] GetResourceAsBytes(Type clazz, string res)
        {
            Debug.Assert(clazz != null && StringUtil.IsNotBlank(res));
            // copy bytes from the stream to an array..
            Stream ins = GetResourceAsStream(clazz, res);

            if (ins == null)
            {
                throw new InvalidOperationException("Resource not found: " + res);
            }

            byte[] buffer = new byte[16 * 1024];
            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = ins.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                QuietClose(ins);
                return(ms.ToArray());
            }
        }
Exemple #7
0
 /// <summary>
 /// Read the entire stream into a String and return it.
 /// </summary>
 /// <param name="clazz"> </param>
 /// <param name="res"></param>
 /// <returns></returns>
 public static string GetResourceAsString(Type clazz, string res)
 {
     Debug.Assert(clazz != null && StringUtil.IsNotBlank(res));
     return(GetResourceAsString(clazz, res, Encoding.UTF8));
 }
Exemple #8
0
 /// <summary>
 /// Returns an input stream of the resource specified.
 /// </summary>
 /// <param name="clazz"> </param>
 /// <param name="resourceName"> </param>
 /// <returns> Returns an InputStream to the resource. </returns>
 public static Stream GetResourceAsStream(Type clazz, string resourceName)
 {
     Debug.Assert(clazz != null && StringUtil.IsNotBlank(resourceName));
     return(clazz.Assembly.GetManifestResourceStream(resourceName));
 }