private static bool Validator_Bool(string text, Nparams param)
            {
                if ((text != null) && (text.Length > 0))
                {
                    switch (text.ToLowerInvariant())
                    {
                    case "1":
                    case "y":
                    case "true":
                    case "yes":
                    case "on":
                        return(true);

                    case "0":
                    case "n":
                    case "false":
                    case "no":
                    case "off":
                        return(true);
                    }
                    bool validValue2;
                    return(bool.TryParse(text, out validValue2));
                }
                return(false);
            }
            private static bool TryParser_NBool(string text, Nparams param, out bool?validValue)
            {
                if ((text != null) && (text.Length > 0))
                {
                    switch (text.ToLowerInvariant())
                    {
                    case "1":
                    case "y":
                    case "true":
                    case "yes":
                    case "on":
                        validValue = true;
                        return(true);

                    case "0":
                    case "n":
                    case "false":
                    case "no":
                    case "off":
                        validValue = false;
                        return(true);
                    }
                    bool validValue2;
                    if (bool.TryParse(text, out validValue2))
                    {
                        validValue = validValue2; return(true);
                    }
                }
                validValue = null; return(false);
            }
            private static bool?Parser_NBool(string text, bool?defaultValue, Nparams param)
            {
                if ((text != null) && (text.Length > 0))
                {
                    switch (text.ToLowerInvariant())
                    {
                    case "1":
                    case "y":
                    case "true":
                    case "yes":
                    case "on":
                        return(true);

                    case "0":
                    case "n":
                    case "false":
                    case "no":
                    case "off":
                        return(false);
                    }
                    bool validValue;
                    if (bool.TryParse(text, out validValue))
                    {
                        return(validValue);
                    }
                }
                return(defaultValue);
            }
Ejemplo n.º 4
0
 /// <summary>
 /// Clears the specified source.
 /// </summary>
 /// <param name="source">The source.</param>
 public static void Clear(this Nparams source)
 {
     if (source != null)
     {
         source._base.Clear();
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds the specified source.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 public static void Add(this Nparams source, string key, object value)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     source._base.Add(key, value);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Tries the get value.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public static bool TryGetValue(this Nparams source, string key, out object value)
 {
     if (source == null)
     {
         value = null; return(false);
     }
     return(source._base.TryGetValue(key, out value));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Sets the specified source.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source">The source.</param>
 /// <param name="value">The value.</param>
 public static void Set <T>(this Nparams source, T value)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     source._base[typeof(T).Name] = value;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Sets the specified source.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source">The source.</param>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 public static void Set <T>(this Nparams source, string key, T value)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     source._base[key] = value;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Adds the range.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="args">The args.</param>
 public static void AddRange(this Nparams source, IDictionary <string, object> args)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     source._base.AddRange(args);
 }
 private static bool Validator_Decimal(string text, Nparams param)
 {
     if ((text != null) && (text.Length > 0))
     {
         decimal validValue;
         return(decimal.TryParse(text, NumberStyles.Currency, null, out validValue));
     }
     return(false);
 }
 private static bool Validator_DateTime(string text, Nparams param)
 {
     if ((text != null) && (text.Length > 0))
     {
         DateTime validValue;
         return(DateTime.TryParse(text, out validValue));
     }
     return(false);
 }
 private static bool Validator_Int32(string text, Nparams param)
 {
     if ((text != null) && (text.Length > 0))
     {
         int validValue;
         return(int.TryParse(text, out validValue));
     }
     return(false);
 }
            private static bool TryParser_String(string text, Nparams param, out string validValue)
            {
                string value2;

                if ((text != null) && ((value2 = text.Trim()).Length > 0))
                {
                    validValue = value2; return(true);
                }
                validValue = default(string); return(false);
            }
            private static string Parser_String(string text, string defaultValue, Nparams param)
            {
                string value2;

                if ((text != null) && ((value2 = text.Trim()).Length > 0))
                {
                    return(value2);
                }
                return(defaultValue);
            }
Ejemplo n.º 15
0
 /// <summary>
 /// Adds the range.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="args">The args.</param>
 public static void AddRange(this Nparams source, Nparams args)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (args != null)
     {
         source._base.AddRange(args._base);
     }
 }
 private static int?Parser_NInt32(string text, int?defaultValue, Nparams param)
 {
     if ((text != null) && (text.Length > 0))
     {
         int validValue;
         if (int.TryParse(text, out validValue))
         {
             return(validValue);
         }
     }
     return(defaultValue);
 }
 private static bool Validator_Default(string text, Nparams param)
 {
     if ((text != null) && (text.Length > 0))
     {
         var args = new object[] { text, default(TResult) };
         if ((bool)_tryParseMethodInfo.Invoke(null, BindingFlags.Default, null, args, null))
         {
             return(true);
         }
     }
     return(false);
 }
 private static bool TryParser_NDateTime(string text, Nparams param, out DateTime?validValue)
 {
     if ((text != null) && (text.Length > 0))
     {
         DateTime validValue2;
         if (DateTime.TryParse(text, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out validValue2))
         {
             validValue = validValue2; return(true);
         }
     }
     validValue = null; return(false);
 }
 private static decimal Parser_Decimal(string text, decimal defaultValue, Nparams param)
 {
     if ((text != null) && (text.Length > 0))
     {
         decimal validValue;
         if (decimal.TryParse(text, NumberStyles.Currency, null, out validValue))
         {
             return(validValue);
         }
     }
     return(defaultValue);
 }
 private static bool TryParser_NDecimal(string text, Nparams param, out decimal?validValue)
 {
     if ((text != null) && (text.Length > 0))
     {
         decimal validValue2;
         if (decimal.TryParse(text, NumberStyles.Currency, null, out validValue2))
         {
             validValue = validValue2; return(true);
         }
     }
     validValue = null; return(false);
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Tries the get value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">The source.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static bool TryGetValue <T>(this Nparams source, string key, out T value)
        {
            if (source == null)
            {
                value = default(T); return(false);
            }
            object valueAsObject;
            var    r = source._base.TryGetValue(key, out valueAsObject);

            value = (T)valueAsObject;
            return(r);
        }
 private static bool TryParser_Default(string text, Nparams param, out TResult validValue)
 {
     if ((text != null) && (text.Length > 0))
     {
         var args = new object[] { text, default(TResult) };
         if ((bool)_tryParseMethodInfo.Invoke(null, BindingFlags.Default, null, args, null))
         {
             validValue = (TResult)args[1]; return(true);
         }
     }
     validValue = default(TResult); return(false);
 }
Ejemplo n.º 23
0
 private static bool TryParser_String(object value, Nparams param, out string validValue)
 {
     if (value != null)
     {
         string text;
         if (((text = (value as string)) != null) && ((text = text.Trim()).Length > 0))
         {
             validValue = text; return(true);
         }
     }
     validValue = default(string); return(false);
 }
Ejemplo n.º 24
0
 private static object Parser2_String(object value, object defaultValue, Nparams param)
 {
     if (value != null)
     {
         string text;
         if (((text = (value as string)) != null) && ((text = text.Trim()).Length > 0))
         {
             return(text);
         }
     }
     return(defaultValue);
 }
 private static bool TryParser_NInt32(string text, Nparams param, out int?validValue)
 {
     if ((text != null) && (text.Length > 0))
     {
         int validValue2;
         if (int.TryParse(text, out validValue2))
         {
             validValue = validValue2; return(true);
         }
     }
     validValue = null; return(false);
 }
 private static object Parser2_Default(string text, object defaultValue, Nparams param)
 {
     if ((text != null) && (text.Length > 0))
     {
         var args = new object[] { text, default(TResult) };
         if ((bool)_tryParseMethodInfo.Invoke(null, BindingFlags.Default, null, args, null))
         {
             return((TResult)args[1]);
         }
     }
     return(defaultValue);
 }
Ejemplo n.º 27
0
            private static bool TryParser_Bool(object value, Nparams param, out bool validValue)
            {
                if (value != null)
                {
                    if (value is bool)
                    {
                        validValue = (bool)value; return(true);
                    }
                    if (value is int)
                    {
                        switch ((int)value)
                        {
                        case 1:
                            validValue = true; return(true);

                        case 0:
                            validValue = false; return(true);
                        }
                        validValue = default(bool); return(false);
                    }
                    string text;
                    if (((text = (value as string)) != null) && (text.Length > 0))
                    {
                        switch (text.ToLowerInvariant())
                        {
                        case "1":
                        case "y":
                        case "true":
                        case "yes":
                        case "on":
                            validValue = true; return(true);

                        case "0":
                        case "n":
                        case "false":
                        case "no":
                        case "off":
                            validValue = false; return(true);
                        }
                        bool validValue2;
                        if (bool.TryParse(text, out validValue2))
                        {
                            validValue = validValue2; return(true);
                        }
                    }
                }
                validValue = default(bool);
                return(false);
            }
Ejemplo n.º 28
0
            private static object Parser2_Bool(object value, object defaultValue, Nparams param)
            {
                if (value != null)
                {
                    if ((value is bool) || (value is bool?))
                    {
                        return(value);
                    }
                    if (value is int)
                    {
                        switch ((int)value)
                        {
                        case 1:
                            return(true);

                        case 0:
                            return(false);
                        }
                        return(defaultValue);
                    }
                    string text;
                    if (((text = (value as string)) != null) && (text.Length > 0))
                    {
                        switch (text.ToLowerInvariant())
                        {
                        case "1":
                        case "y":
                        case "true":
                        case "yes":
                        case "on":
                            return(true);

                        case "0":
                        case "n":
                        case "false":
                        case "no":
                        case "off":
                            return(false);
                        }
                        bool validValue;
                        if (bool.TryParse(text, out validValue))
                        {
                            return(validValue);
                        }
                    }
                }
                return(defaultValue);
            }
Ejemplo n.º 29
0
 private static bool Validator_Decimal(object value, Nparams param)
 {
     if (value != null)
     {
         if (value is decimal)
         {
             return(true);
         }
         string text;
         if (((text = (value as string)) != null) && (text.Length > 0))
         {
             decimal validValue;
             return(decimal.TryParse(text, NumberStyles.Currency, null, out validValue));
         }
     }
     return(false);
 }
Ejemplo n.º 30
0
 private static bool Validator_DateTime(object value, Nparams param)
 {
     if (value != null)
     {
         if (value is DateTime)
         {
             return(true);
         }
         string text;
         if (((text = (value as string)) != null) && (text.Length > 0))
         {
             DateTime validValue;
             return(DateTime.TryParse(text, out validValue));
         }
     }
     return(false);
 }