Created
December 23, 2022 05:33
-
-
Save LuviKunG/e93497a4aa27201815b8c9cf9b7ac352 to your computer and use it in GitHub Desktop.
Manageable instance class of scripting define symbols group.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
/// <summary> | |
/// Manageable instance class of scripting define symbols group. | |
/// </summary> | |
public sealed class ScriptingDefineSymbols | |
{ | |
private const char SDS_SEPARATOR = ';'; | |
private HashSet<string> m_list; | |
/// <summary> | |
/// Create Scripting define symbols. | |
/// </summary> | |
public ScriptingDefineSymbols() | |
{ | |
m_list = new HashSet<string>(); | |
} | |
/// <summary> | |
/// Create Scripting define symbols with group of symbols. | |
/// </summary> | |
/// <param name="groupSymbols">Group of symbols.</param> | |
public ScriptingDefineSymbols(string groupSymbols) : this() | |
{ | |
AddGroup(groupSymbols); | |
} | |
/// <summary> | |
/// Create Scripting define symbols with group of symbols. | |
/// </summary> | |
/// <param name="symbols">Symbols.</param> | |
public ScriptingDefineSymbols(params string[] symbols) : this() | |
{ | |
AddRange(symbols); | |
} | |
/// <summary> | |
/// Create Scripting define symbols with group of symbols. | |
/// </summary> | |
/// <param name="symbols">Iterator of symbols.</param> | |
public ScriptingDefineSymbols(IEnumerable<string> symbols) : this() | |
{ | |
AddRange(symbols); | |
} | |
/// <summary> | |
/// Add new scripting define symbol to the group. | |
/// </summary> | |
/// <param name="symbol">Symbol.</param> | |
public void Add(string symbol) | |
{ | |
if (string.IsNullOrEmpty(symbol)) | |
return; | |
m_list.Add(symbol); | |
} | |
/// <summary> | |
/// Add new scripting define symbols to the group. | |
/// </summary> | |
/// <param name="groupSymbols">Group symbols.</param> | |
public void AddGroup(string groupSymbols) | |
{ | |
string[] symbols = groupSymbols.Split(SDS_SEPARATOR); | |
AddRange(symbols); | |
} | |
/// <summary> | |
/// Add new scripting define symbols to the group. | |
/// </summary> | |
/// <param name="symbols">Iteratable symbols.</param> | |
public void AddRange(IEnumerable<string> symbols) | |
{ | |
foreach (string symbol in symbols) | |
Add(symbol); | |
} | |
/// <summary> | |
/// Remove exist scripting define symbol from the group. | |
/// </summary> | |
/// <param name="symbol">Symbol.</param> | |
public void Remove(string symbol) | |
{ | |
if (string.IsNullOrEmpty(symbol)) | |
return; | |
m_list.Remove(symbol); | |
} | |
/// <summary> | |
/// Clear all scripting define symbols. | |
/// </summary> | |
public void Clear() | |
{ | |
m_list.Clear(); | |
} | |
/// <summary> | |
/// Convert current scripting define symbols to group symbols. | |
/// </summary> | |
/// <returns>Group symbols.</returns> | |
public string ToGroupSymbols() | |
{ | |
if (m_list.Count > 0) | |
return string.Join(SDS_SEPARATOR, m_list); | |
else | |
return null; | |
} | |
/// <summary> | |
/// Get the scripting define symbols as a string. | |
/// Return same as <see cref="ToGroupSymbols"/> | |
/// </summary> | |
/// <returns>Group symbols.</returns> | |
public override string ToString() | |
{ | |
return ToGroupSymbols(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment