Class Properties
- Namespace
- Ice
- Assembly
- Ice.dll
Represents a set of properties used to configure Ice and Ice-based applications. A property is a key/value pair,
where both the key and the value are strings. By convention, property keys should have the form
application-name[.category[.sub-category]].name.
public sealed class Properties
- Inheritance
-
Properties
- Inherited Members
Remarks
This class is thread-safe: multiple threads can safely read and write the properties.
Constructors
Properties()
Initializes a new instance of the Properties class. The property set is initially empty.
public Properties()
Properties(ref string[], Properties?)
Initializes a new instance of the Properties class, loads the configuration files specified by
the Ice.Config property or the ICE_CONFIG environment variable, and then parses Ice properties
from args.
public Properties(ref string[] args, Properties? defaults = null)
Parameters
argsstring[]The command-line arguments. This constructor parses arguments starting with
--and one of the reserved prefixes (Ice, IceSSL, etc.) as properties and removes these elements from the list. If there is an argument starting with--Ice.Config, this constructor loads the specified configuration file. When the same property is set in a configuration file and through a command-line argument, the command-line setting takes precedence.defaultsPropertiesDefault values for the new Properties object. Settings in configuration files and the arguments override these defaults.
Remarks
This constructor loads properties from files specified by the ICE_CONFIG environment variable
when there is no --Ice.Config command-line argument.
Methods
Clone()
Create a copy of this property set.
public Properties Clone()
Returns
- Properties
A copy of this property set.
getCommandLineOptions()
Get a sequence of command-line options that is equivalent to this property set. Each element of the returned sequence is a command-line option of the form --key=value.
public string[] getCommandLineOptions()
Returns
- string[]
The command line options for this property set.
getIceProperty(string)
Get an Ice property by key. If the property is not set, its default value is returned.
public string getIceProperty(string key)
Parameters
keystringThe property key.
Returns
- string
The property value or the default value.
Exceptions
- PropertyException
Thrown when the property is not a known Ice property.
getIcePropertyAsInt(string)
Get an Ice property as an integer. If the property is not set, its default value is returned.
public int getIcePropertyAsInt(string key)
Parameters
keystringThe property key.
Returns
- int
The property value interpreted as an integer, or the default value.
Exceptions
- PropertyException
Thrown when the property is not a known Ice property or the value is not a valid integer.
getIcePropertyAsList(string)
Get an Ice property as a list of strings. The strings must be separated by whitespace or comma. If the property is not set, its default list is returned. The strings in the list can contain whitespace and commas if they are enclosed in single or double quotes. If quotes are mismatched, the default list is returned. Within single quotes or double quotes, you can escape the quote in question with a backslash, e.g. O'Reilly can be written as "O'Reilly" or 'O'Reilly'.
public string[] getIcePropertyAsList(string key)
Parameters
keystringThe property key.
Returns
- string[]
The property value interpreted as list of strings, or the default value.
Exceptions
- PropertyException
Thrown when the property is not a known Ice property.
getPropertiesForPrefix(string)
Get all properties whose keys begin with prefix.
If prefix is an empty string, then all
properties are returned.
public Dictionary<string, string> getPropertiesForPrefix(string prefix)
Parameters
prefixstringThe prefix to search for (empty string if none).
Returns
- Dictionary<string, string>
The matching property set.
getProperty(string)
Get a property by key. If the property is not set, an empty string is returned.
public string getProperty(string key)
Parameters
keystringThe property key.
Returns
- string
The property value.
getPropertyAsInt(string)
Get a property as an integer. If the property is not set, 0 is returned.
public int getPropertyAsInt(string key)
Parameters
keystringThe property key.
Returns
- int
The property value interpreted as an integer.
Exceptions
- PropertyException
Thrown when the property value is not a valid integer.
getPropertyAsIntWithDefault(string, int)
Get a property as an integer. If the property is not set, the given default value is returned.
public int getPropertyAsIntWithDefault(string key, int value)
Parameters
Returns
- int
The property value interpreted as an integer, or the default value.
Exceptions
- PropertyException
Thrown when the property value is not a valid integer.
getPropertyAsList(string)
Get a property as a list of strings. The strings must be separated by whitespace or comma. If the property is not set, an empty list is returned. The strings in the list can contain whitespace and commas if they are enclosed in single or double quotes. If quotes are mismatched, an empty list is returned. Within single quotes or double quotes, you can escape the quote in question with a backslash, e.g. O'Reilly can be written as "O'Reilly" or 'O'Reilly'.
public string[] getPropertyAsList(string key)
Parameters
keystringThe property key.
Returns
- string[]
The property value interpreted as a list of strings.
getPropertyAsListWithDefault(string, string[])
Get a property as a list of strings. The strings must be separated by whitespace or comma. If the property is not set, the default list is returned. The strings in the list can contain whitespace and commas if they are enclosed in single or double quotes. If quotes are mismatched, the default list is returned. Within single quotes or double quotes, you can escape the quote in question with a backslash, e.g. O'Reilly can be written as "O'Reilly" or 'O'Reilly'.
public string[] getPropertyAsListWithDefault(string key, string[] value)
Parameters
Returns
- string[]
The property value interpreted as list of strings, or the default value.
getPropertyWithDefault(string, string)
Get a property by key. If the property is not set, the given default value is returned.
public string getPropertyWithDefault(string key, string value)
Parameters
Returns
- string
The property value or the default value.
getUnusedProperties()
Get the unused properties in the property set.
public List<string> getUnusedProperties()
Returns
ice_clone_()
Alias for Clone(). Provided for source compatibility with Ice 3.7 and earlier versions.
[Obsolete("Use Clone instead.")]
public Properties ice_clone_()
Returns
- Properties
A copy of this property set.
load(string)
Load properties from a file.
public void load(string file)
Parameters
filestringThe property file.
parseCommandLineOptions(string, string[])
Convert a sequence of command-line options into properties. All options that begin with --prefix. are converted into properties. If the prefix is empty, all options that begin with -- are converted to properties.
public string[] parseCommandLineOptions(string prefix, string[] options)
Parameters
prefixstringThe property prefix, or an empty string to convert all options starting with --.
optionsstring[]The command-line options.
Returns
- string[]
The command-line options that do not start with the specified prefix, in their original order.
parseIceCommandLineOptions(string[])
Convert a sequence of command-line options into properties. All options that begin with one of the reserved Ice prefixes (--Ice, --IceSSL, --IceBox, etc.) are converted into properties.
public string[] parseIceCommandLineOptions(string[] options)
Parameters
optionsstring[]The command-line options.
Returns
- string[]
The command-line options that do not start with one of the reserved prefixes, in their original order.
setProperty(string, string)
Set a property. To unset a property, set it to the empty string.
public void setProperty(string key, string value)