C# Class Kajabity.Tools.Java.JavaProperties

Hold Java style properties as key-value pairs and allow them to be loaded from or saved to a ".properties" file. The file is stored with character set ISO-8859-1 which extends US-ASCII (the characters 0-127 are the same) and forms the first part of the Unicode character set. Within the application string are Unicode - but all values outside the basic US-ASCII set are escaped.
Inheritance: System.Collections.Hashtable
显示文件 Open project: Kajabity/Kajabity-Tools Class Usage Examples

Protected Properties

Property Type Description
defaults System.Collections.Hashtable

Private Properties

Property Type Description
AsString string

Public Methods

Method Description
GetProperty ( string key ) : string

Get the value for the specified key value. If the key is not found, then return the default value - and if still not found, return null.

GetProperty ( string key, string defaultValue ) : string

Get the value for the specified key value. If the key is not found, then return the default value - and if still not found, return defaultValue.

JavaProperties ( ) : System

An empty constructor that doesn't set the defaults.

JavaProperties ( Hashtable defaults ) : System

Use this constructor to provide a set of default values. The default values are kept separate to the ones in this instant.

Load ( Stream streamIn ) : void

Load Java Properties from a stream expecting the format as described in JavaPropertyReader.

Load ( Stream streamIn, Encoding encoding ) : void

Load Java Properties from a stream with the specified encoding and expecting the format as described in JavaPropertyReader.

PropertyNames ( ) : IEnumerator

Returns an enumerator of all the properties available in this instance - including the defaults.

SetProperty ( string key, string newValue ) : string

Set the value for a property key. The old value is returned - if any.

Store ( Stream streamOut, string comments ) : void

Store the contents of this collection of properties to the stream in the format used for Java ".properties" files using an instance of JavaPropertyWriter. The keys and values will be minimally escaped to ensure special characters are read back in properly. Keys are not sorted. The file will begin with a comment identifying the date - and an additional comment may be included.

Private Methods

Method Description
AsString ( Object o ) : string

A utility method to safely convert an Object to a string.

Method Details

GetProperty() public method

Get the value for the specified key value. If the key is not found, then return the default value - and if still not found, return null.
public GetProperty ( string key ) : string
key string The key whose value should be returned.
return string

GetProperty() public method

Get the value for the specified key value. If the key is not found, then return the default value - and if still not found, return defaultValue.
public GetProperty ( string key, string defaultValue ) : string
key string The key whose value should be returned.
defaultValue string The default value if the key is not found.
return string

JavaProperties() public method

An empty constructor that doesn't set the defaults.
public JavaProperties ( ) : System
return System

JavaProperties() public method

Use this constructor to provide a set of default values. The default values are kept separate to the ones in this instant.
public JavaProperties ( Hashtable defaults ) : System
defaults System.Collections.Hashtable A Hashtable that holds a set of defafult key value pairs to /// return when the requested key has not been set.
return System

Load() public method

Load Java Properties from a stream expecting the format as described in JavaPropertyReader.
If the stream source is invalid.
public Load ( Stream streamIn ) : void
streamIn Stream An input stream to read properties from.
return void

Load() public method

Load Java Properties from a stream with the specified encoding and expecting the format as described in JavaPropertyReader.
public Load ( Stream streamIn, Encoding encoding ) : void
streamIn Stream An input stream to read properties from.
encoding System.Text.Encoding The stream's encoding.
return void

PropertyNames() public method

Returns an enumerator of all the properties available in this instance - including the defaults.
public PropertyNames ( ) : IEnumerator
return IEnumerator

SetProperty() public method

Set the value for a property key. The old value is returned - if any.
public SetProperty ( string key, string newValue ) : string
key string The key whose value is to be set.
newValue string The new value off the key.
return string

Store() public method

Store the contents of this collection of properties to the stream in the format used for Java ".properties" files using an instance of JavaPropertyWriter. The keys and values will be minimally escaped to ensure special characters are read back in properly. Keys are not sorted. The file will begin with a comment identifying the date - and an additional comment may be included.
public Store ( Stream streamOut, string comments ) : void
streamOut Stream An output stream to write the properties to.
comments string Optional additional comment to include at the head of the output.
return void

Property Details

defaults protected_oe property

A reference to an optional set of default properties - these values are returned if the value has not been loaded from a ".properties" file or set programatically.
protected Hashtable,System.Collections defaults
return System.Collections.Hashtable