using System.Collections.Generic;
namespace Unity.Services.Core
{
///
/// Contain all options to customize services initialization when
/// calling .
///
public class InitializationOptions
{
IDictionary m_Values;
internal IEnumerable> Values => m_Values;
///
/// Create a new instance of the class.
///
public InitializationOptions()
: this(new Dictionary()) {}
internal InitializationOptions(IDictionary values)
{
m_Values = values;
}
///
/// Get the option for the given if any.
///
///
/// The key of the option to retrieve.
///
///
/// The stored option if any.
///
///
/// Return true if there is a bool for the given ;
/// return false otherwise.
///
public bool TryGetOption(string key, out bool option)
{
return TryGetOption(key, out option);
}
///
/// Get the option for the given if any.
///
///
/// The key of the option to retrieve.
///
///
/// The stored option if any.
///
///
/// Return true if there is a int for the given ;
/// return false otherwise.
///
public bool TryGetOption(string key, out int option)
{
return TryGetOption(key, out option);
}
///
/// Get the option for the given if any.
///
///
/// The key of the option to retrieve.
///
///
/// The stored option if any.
///
///
/// Return true if there is a float for the given ;
/// return false otherwise.
///
public bool TryGetOption(string key, out float option)
{
return TryGetOption(key, out option);
}
///
/// Get the option for the given if any.
///
///
/// The key of the option to retrieve.
///
///
/// The stored option if any.
///
///
/// Return true if there is a string for the given ;
/// return false otherwise.
///
public bool TryGetOption(string key, out string option)
{
return TryGetOption(key, out option);
}
bool TryGetOption(string key, out T option)
{
option = default;
if (m_Values.TryGetValue(key, out var rawValue)
&& rawValue is T value)
{
option = value;
return true;
}
return false;
}
///
/// Stores the given for the given .
///
///
/// The identifier of the configuration entry.
///
///
/// The value to store.
///
///
/// Return this instance.
///
public InitializationOptions SetOption(string key, bool value)
{
m_Values[key] = value;
return this;
}
///
/// Stores the given for the given .
///
///
/// The identifier of the configuration entry.
///
///
/// The value to store.
///
///
/// Return this instance.
///
public InitializationOptions SetOption(string key, int value)
{
m_Values[key] = value;
return this;
}
///
/// Stores the given for the given .
///
///
/// The identifier of the configuration entry.
///
///
/// The value to store.
///
///
/// Return this instance.
///
public InitializationOptions SetOption(string key, float value)
{
m_Values[key] = value;
return this;
}
///
/// Stores the given for the given .
///
///
/// The identifier of the configuration entry.
///
///
/// The value to store.
///
///
/// Return this instance.
///
public InitializationOptions SetOption(string key, string value)
{
m_Values[key] = value;
return this;
}
}
}