GetProperty() public method

Gets a property from the configuration. *
public GetProperty ( String key ) : Object
key String property to retrieve ///
return Object
Beispiel #1
0
        public static ExtendedProperties ConvertProperties(ExtendedProperties p)
        {
            ExtendedProperties properties = new ExtendedProperties();
            IEnumerator        keys       = p.Keys;

            while (keys.MoveNext())
            {
                string current = (string)keys.Current;
                string str2    = p.GetProperty(current).ToString();
                properties.SetProperty(current, str2);
            }
            return(properties);
        }
        public static ExtendedProperties ConvertProperties(ExtendedProperties p)
        {
            ExtendedProperties extendedProperties = new ExtendedProperties();

            foreach (string key in p.Keys)
            {
                object obj = p.GetProperty(key);
                if (obj is string)
                {
                    obj = obj.ToString().Replace(",", "\\,");
                }
                extendedProperties.SetProperty(key, obj);
            }
            return(extendedProperties);
        }
Beispiel #3
0
        public void Test_ExtendedProperties()
        {
            FileInfo file = new FileInfo("test1.properties");
            StreamWriter sw = file.CreateText();
            sw.WriteLine("# lines starting with # are comments.  Blank lines are ignored");
            sw.WriteLine("");
            sw.WriteLine("# This is the simplest property");
            sw.WriteLine("key = value");
            sw.WriteLine("");
            sw.WriteLine("# A long property may be separated on multiple lines");
            sw.WriteLine("longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \\");
            sw.WriteLine("            aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            sw.WriteLine("");
            sw.WriteLine("# This is a property with many tokens");
            sw.WriteLine("tokens_on_a_line = first token, second token");
            sw.WriteLine("");
            sw.WriteLine("# This sequence generates exactly the same result");
            sw.WriteLine("tokens_on_multiple_lines = first token");
            sw.WriteLine("tokens_on_multiple_lines = second token");
            sw.WriteLine("");
            sw.WriteLine("# commas may be escaped in tokens");
            sw.WriteLine("commas.excaped = Hi\\, what'up?");
            sw.Flush();
            sw.Close();

            StreamReader sr = file.OpenText();
            String s = sr.ReadToEnd();
            sr.Close();

            // TODO: could build string, then write, then read and compare.
            ExtendedProperties props = new ExtendedProperties(file.FullName);

            Assertion.Assert("expected to have 5 properties, had " + props.Count.ToString(), props.Count==5);

            Assertion.Assert("key was not correct: " + props.GetString("key"), props.GetString("key").Equals("value"));
            Assertion.Assert("commas.excaped was not correct: " + props.GetString("commas.excaped"), props.GetString("commas.excaped").Equals("Hi, what'up?"));

            Object o = props.GetProperty("tokens_on_a_line");
            Assertion.Assert("tokens_on_a_line was expected to be an ArrayList", (o is ArrayList));
            Assertion.Assert("tokens_on_a_line was expected to be an ArrayList with 2 elements", ((ArrayList)o).Count==2);

            StringWriter writer = new StringWriter();
            props.Save(writer, "header");
        }
		private void LoadMacros(ExtendedProperties props)
		{
			var macros = ViewSourceLoader.ListViews("macros",this.ViewFileExtension,this.JSGeneratorFileExtension);

			var macroList = new ArrayList(macros);

			if (macroList.Count > 0)
			{
				var libPropValue = props.GetProperty(RuntimeConstants.VM_LIBRARY);

				if (libPropValue is ICollection)
				{
					macroList.AddRange((ICollection) libPropValue);
				}
				else if (libPropValue is string)
				{
					macroList.Add(libPropValue);
				}

				props.AddProperty(RuntimeConstants.VM_LIBRARY, macroList);
			}

			props.AddProperty(RuntimeConstants.VM_LIBRARY_AUTORELOAD, true);
		}
Beispiel #5
0
		/// <summary>
		/// Convert a standard properties class into a configuration class.
		/// </summary>
		/// <param name="p">properties object to convert into a ExtendedProperties object.</param>
		/// <returns>ExtendedProperties configuration created from the properties object.</returns>
		public static ExtendedProperties ConvertProperties(ExtendedProperties p)
		{
			ExtendedProperties c = new ExtendedProperties();

			foreach(String key in p.Keys)
			{
				Object value = p.GetProperty(key);

				// if the value is a String, escape it so that if there are delimiters that the value is not converted to a list
				if (value is String)
					value = value.ToString().Replace(",", @"\,");
				c.SetProperty(key, value);
			}

			return c;
		}
	/// <summary> Convert a standard properties class into a configuration
	/// class.
	/// *
	/// </summary>
	/// <param name="p">properties object to convert into
	/// a ExtendedProperties object.
	/// *
	/// </param>
	/// <returns>ExtendedProperties configuration created from the
	/// properties object.
	///
	/// </returns>

	public static ExtendedProperties ConvertProperties(ExtendedProperties p) {
	    ExtendedProperties c = new ExtendedProperties();

	    for (IEnumerator e = (IEnumerator) p.Keys; e.MoveNext(); ) {
		String key = (String) e.Current;
		String value = p.GetProperty(key).ToString();
		c.SetProperty(key, value);
	    }

	    return c;
	}
		private void LoadMacros(ExtendedProperties props)
		{
			String[] macros = ViewSourceLoader.ListViews("macros");

			ArrayList macroList = new ArrayList(macros);

			if (macroList.Count > 0)
			{
				object libPropValue = props.GetProperty(RuntimeConstants.VM_LIBRARY);

				if (libPropValue is ICollection)
				{
					macroList.AddRange((ICollection) libPropValue);
				}
				else if (libPropValue is string)
				{
					macroList.Add(libPropValue);
				}

				props.AddProperty(RuntimeConstants.VM_LIBRARY, macroList);
			}

			props.AddProperty(RuntimeConstants.VM_LIBRARY_AUTORELOAD, true);
		}