Commons.Collections.ExtendedProperties.GetBoolean C# (CSharp) Method

GetBoolean() public method

Get a boolean associated with the given configuration key. *
is thrown if the key maps to an /// object that is not a Boolean. /// ///
public GetBoolean ( String key, System.Boolean defaultValue ) : System.Boolean
key String The configuration key. ///
defaultValue System.Boolean The default value. ///
return System.Boolean
        public Boolean GetBoolean(String key, Boolean defaultValue)
        {
            Object value = this[key];

            if (value is Boolean)
            {
                return (Boolean) value;
            }
            else if (value is String)
            {
                String s = TestBoolean((String) value);
                Boolean b = s.ToUpper().Equals("TRUE");
                CollectionsUtil.PutElement(this, key, b);
                return b;
            }
            else if (value == null)
            {
                if (defaults == null)
                {
                    return defaultValue;
                }
                else
                {
                    return defaults.GetBoolean(key, defaultValue);
                }
            }
            else
            {
                throw new InvalidCastException(string.Format("{0}{1}' doesn't map to a Boolean object", '\'', key));
            }
        }

Same methods

ExtendedProperties::GetBoolean ( String key ) : bool

Usage Example

		/// <summary>
		/// This initialization is used by all resource
		/// loaders and must be called to set up common
		/// properties shared by all resource loaders
		/// </summary>
		public void CommonInit(IRuntimeServices rs, ExtendedProperties configuration)
		{
			rsvc = rs;

			// these two properties are not required for all loaders.
			// For example, for ClasspathLoader, what would cache mean? 
			// so adding default values which I think are the safest

			// don't cache, and modCheckInterval irrelevant...

			isCachingOn = configuration.GetBoolean("cache", false);
			modificationCheckInterval = configuration.GetLong("modificationCheckInterval", 0);

			// this is a must!
			className = configuration.GetString("class");
		}
All Usage Examples Of Commons.Collections.ExtendedProperties::GetBoolean