Class ConfigAsset
Config asset type. This asset loads a config file (.ini format in default implementation) and provide API to retrieve or set data from it.
Implements
Inherited Members
Namespace: BonEngineSharp.Assets
Assembly: BonEngineSharp.dll
Syntax
public class ConfigAsset : IAsset, IDisposable
Constructors
ConfigAsset(IntPtr)
Create the asset.
Declaration
public ConfigAsset(IntPtr handle)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IntPtr | handle | Asset handle inside the low-level engine. |
Properties
AssetType
Get asset type.
Declaration
public override AssetType AssetType { get; }
Property Value
| Type | Description |
|---|---|
| AssetType |
Overrides
Methods
Exists(String)
Return if a section exists.
Declaration
public bool Exists(string section)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to check if exists. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if section exists, false otherwise. |
Exists(String, String)
Return if a key exists in section.
Declaration
public bool Exists(string section, string key)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to check if exists. |
| System.String | key | Key to check if exists. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if section exists, false otherwise. |
Finalize()
Dispose on destructor.
Declaration
protected override void Finalize()
Overrides
GetAllReadKeys()
Return enumerable with all keys that were read. Format is 'section.key'.
Declaration
public IEnumerable<string> GetAllReadKeys()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<System.String> | Enumerable with all keys read. |
GetAllUnreadKeys()
Return enumerable with all keys that were not read from this config file. This method is useful to detect useless keys in file. Format is 'section.key'.
Declaration
public IEnumerable<string> GetAllUnreadKeys()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<System.String> | Enumerable with all unread keys. |
GetBool(String, String, Boolean)
Get a bool value from config.
Declaration
public bool GetBool(string section, string key, bool defaultVal = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to get value from. |
| System.String | key | Key to get. |
| System.Boolean | defaultVal | Default value to return if not found. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Value from config, or defaultVal if not found. |
GetColor(String, String, Color)
Get Color from config (from bytes, ie 0-255 values: r,g,b,a).
Declaration
public Color GetColor(string section, string key, Color defaultVal)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to get value from. |
| System.String | key | Key to get. |
| Color | defaultVal | Default value to return if not found. |
Returns
| Type | Description |
|---|---|
| Color | Value from config, or defaultVal if not found. |
GetFloat(String, String, Single)
Get a float value from config.
Declaration
public float GetFloat(string section, string key, float defaultVal = 0F)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to get value from. |
| System.String | key | Key to get. |
| System.Single | defaultVal | Default value to return if not found. |
Returns
| Type | Description |
|---|---|
| System.Single | Value from config, or defaultVal if not found. |
GetGeneric<T>(String, String, T)
Get generic type by trying to convert string to given type.
Declaration
public T GetGeneric<T>(string section, string key, T defaultVal)
where T : struct, IConvertible, ValueType
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to get value from. |
| System.String | key | Key to get. |
| T | defaultVal | Default value to return if not found. |
Returns
| Type | Description |
|---|---|
| T | Value from config, or defaultVal if not found. |
Type Parameters
| Name | Description |
|---|---|
| T | Type to convert to. |
GetInt(String, String, Int32)
Get an int value from config.
Declaration
public int GetInt(string section, string key, int defaultVal = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to get value from. |
| System.String | key | Key to get. |
| System.Int32 | defaultVal | Default value to return if not found. |
Returns
| Type | Description |
|---|---|
| System.Int32 | Value from config, or defaultVal if not found. |
GetPointF(String, String, PointF)
Get PointF from config.
Declaration
public PointF GetPointF(string section, string key, PointF defaultVal)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to get value from. |
| System.String | key | Key to get. |
| PointF | defaultVal | Default value to return if not found. |
Returns
| Type | Description |
|---|---|
| PointF | Value from config, or defaultVal if not found. |
GetPointI(String, String, PointI)
Get PointI from config.
Declaration
public PointI GetPointI(string section, string key, PointI defaultVal)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to get value from. |
| System.String | key | Key to get. |
| PointI | defaultVal | Default value to return if not found. |
Returns
| Type | Description |
|---|---|
| PointI | Value from config, or defaultVal if not found. |
GetRectangleF(String, String, RectangleF)
Get RectangleF from config.
Declaration
public RectangleF GetRectangleF(string section, string key, RectangleF defaultVal)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to get value from. |
| System.String | key | Key to get. |
| RectangleF | defaultVal | Default value to return if not found. |
Returns
| Type | Description |
|---|---|
| RectangleF | Value from config, or defaultVal if not found. |
GetRectangleI(String, String, RectangleI)
Get RectangleI from config.
Declaration
public RectangleI GetRectangleI(string section, string key, RectangleI defaultVal)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to get value from. |
| System.String | key | Key to get. |
| RectangleI | defaultVal | Default value to return if not found. |
Returns
| Type | Description |
|---|---|
| RectangleI | Value from config, or defaultVal if not found. |
GetStr(String, String, String)
Get a string value from config.
Declaration
public string GetStr(string section, string key, string defaultVal = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to get value from. |
| System.String | key | Key to get. |
| System.String | defaultVal | Default value to return if not found. |
Returns
| Type | Description |
|---|---|
| System.String | Value from config, or defaultVal if not found. |
Keys(String)
Get all keys in a section.
Declaration
public string[] Keys(string section)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to get keys from. |
Returns
| Type | Description |
|---|---|
| System.String[] |
ReadInto(String, Object, Action<MemberInfo>, Action<MemberInfo>)
Read a section into an object, by using all public fields as keys.
Declaration
public void ReadInto(string section, object obj, Action<MemberInfo> onUnsupportedType = null, Action<MemberInfo> onMissingFields = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to read. |
| System.Object | obj | Object to read values into. |
| System.Action<System.Reflection.MemberInfo> | onUnsupportedType | Optional callback to call for every field we don't know how to parse. |
| System.Action<System.Reflection.MemberInfo> | onMissingFields | Optional callback to call for every public field we don't have a key for in the ini file. |
RemoveKey(String, String)
Remove a key from config.
Declaration
public void RemoveKey(string section, string key)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to remove key from. |
| System.String | key | Key to remove. |
Sections()
Get all sections in config.
Declaration
public string[] Sections()
Returns
| Type | Description |
|---|---|
| System.String[] |
SetValue(String, String, Object)
Set value in config.
Declaration
public void SetValue(string section, string key, object value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | section | Section to set value in. |
| System.String | key | Key to set. |
| System.Object | value | Value to set (will be stringified with ToString()). |
ToIniString()
Convert this config to string in ini format.
Declaration
public string ToIniString()
Returns
| Type | Description |
|---|---|
| System.String | Config as ini file string. |