Class SystemProperties
Helper for environment variables. This class helps to convert the environment variables to int or bool data types and also silently handles read permission errors.
For instructions how to set environment variables for your OS, see https://www.schrodinger.com/kb/1842.
Note that if you want to load any of these settings for your application from a configuration file, it is recommended your application load them at startup and call SetProperty(String, String) to set them.
Set the environment variable lucene.ignoreSecurityExceptions
to false
to change the read behavior of these methods to throw the underlying exception
instead of returning the default value.
Inheritance
Inherited Members
Namespace: Lucene.Net.Support
Assembly: Lucene.Net.dll
Syntax
public static class SystemProperties
Methods
| Improve this Doc View SourceGetProperty(String)
Retrieves the value of an environment variable from the current process.
Declaration
public static string GetProperty(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The name of the environment variable. |
Returns
Type | Description |
---|---|
System.String | The environment variable value. |
GetProperty(String, String)
Retrieves the value of an environment variable from the current process, with a default value if it doens't exist or the caller doesn't have permission to read the value.
Declaration
public static string GetProperty(string key, string defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The name of the environment variable. |
System.String | defaultValue | The value to use if the environment variable does not exist or the caller doesn't have permission to read the value. |
Returns
Type | Description |
---|---|
System.String | The environment variable value. |
GetPropertyAsBoolean(String)
Retrieves the value of an environment variable from the current process
as System.Boolean. If the value cannot be cast to System.Boolean, returns false
.
Declaration
public static bool GetPropertyAsBoolean(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The name of the environment variable. |
Returns
Type | Description |
---|---|
System.Boolean | The environment variable value. |
GetPropertyAsBoolean(String, Boolean)
Retrieves the value of an environment variable from the current process as System.Boolean, with a default value if it doens't exist, the caller doesn't have permission to read the value, or the value cannot be cast to a System.Boolean.
Declaration
public static bool GetPropertyAsBoolean(string key, bool defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The name of the environment variable. |
System.Boolean | defaultValue | The value to use if the environment variable does not exist, the caller doesn't have permission to read the value, or the value cannot be cast to System.Boolean. |
Returns
Type | Description |
---|---|
System.Boolean | The environment variable value. |
GetPropertyAsInt32(String)
Retrieves the value of an environment variable from the current process
as System.Int32. If the value cannot be cast to System.Int32, returns 0
.
Declaration
public static int GetPropertyAsInt32(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The name of the environment variable. |
Returns
Type | Description |
---|---|
System.Int32 | The environment variable value. |
GetPropertyAsInt32(String, Int32)
Retrieves the value of an environment variable from the current process as System.Int32, with a default value if it doens't exist, the caller doesn't have permission to read the value, or the value cannot be cast to a System.Int32.
Declaration
public static int GetPropertyAsInt32(string key, int defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The name of the environment variable. |
System.Int32 | defaultValue | The value to use if the environment variable does not exist, the caller doesn't have permission to read the value, or the value cannot be cast to System.Int32. |
Returns
Type | Description |
---|---|
System.Int32 | The environment variable value. |
SetProperty(String, String)
Creates, modifies, or deletes an environment variable stored in the current process.
Declaration
public static void SetProperty(string key, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The name of the environment variable. |
System.String | value | The new environment variable value. |
Exceptions
Type | Condition |
---|---|
System.Security.SecurityException | The caller does not have the required permission to perform this operation. |