Added new section to handle the PreventTransferForClassNames settings.

This commit is contained in:
Brett Hewitson 2021-06-19 15:34:44 +10:00
parent afa461f956
commit a54f1e5381
17 changed files with 484 additions and 35 deletions

View file

@ -35,13 +35,23 @@ namespace ServerManagerTool.Common.Attibutes
public int BracketsAroundValueDelimiter = 1;
/// <summary>
/// If true, then the property with not be written if empty. This does not work for collections, only value types.
/// If true, then the property will not be written if empty. This does not work for collections, only value types.
/// </summary>
public bool ExcludeIfEmpty;
/// <summary>
/// If true, then the property with not be written if false. This does not work for collections, only BOOLEAN types.
/// If true, then the property will not be written if false. This does not work for collections, only BOOLEAN types.
/// </summary>
public bool ExcludeIfFalse = false;
/// <summary>
/// If true, the value will always be written with quotes; otherwise without quotes.
/// </summary>
public bool QuotedString = true;
/// <summary>
/// If true, then the property name will not be written. This does not work for collections, only value types.
/// </summary>
public bool ExcludePropertyName = false;
}
}

View file

@ -113,7 +113,7 @@ namespace ServerManagerTool.Common.Model
var propName = string.IsNullOrWhiteSpace(attr?.Key) ? prop.Name : attr.Key;
var val = prop.GetValue(this);
var propValue = StringUtils.GetPropertyValue(val, prop);
var propValue = StringUtils.GetPropertyValue(val, prop, attr?.QuotedString ?? true);
if ((attr?.ExcludeIfEmpty ?? false) && string.IsNullOrWhiteSpace(propValue))
{
@ -121,7 +121,9 @@ namespace ServerManagerTool.Common.Model
}
else
{
result.Append($"{propName}={propValue}");
if (!(attr?.ExcludePropertyName ?? false))
result.Append($"{propName}=");
result.Append($"{propValue}");
delimiter = DELIMITER.ToString();
}
@ -242,10 +244,11 @@ namespace ServerManagerTool.Common.Model
}
else
{
var propValue = StringUtils.GetPropertyValue(val, prop);
var propValue = StringUtils.GetPropertyValue(val, prop, attr?.QuotedString ?? true);
result.Append(delimiter);
result.Append($"{propName}=");
if (!(attr?.ExcludePropertyName ?? false))
result.Append($"{propName}=");
if (attr?.ValueWithinBrackets ?? false)
result.Append("(");

View file

@ -10,14 +10,19 @@ namespace ServerManagerTool.Common.Utils
{
public const string DEFAULT_CULTURE_CODE = "en-US";
public static string GetPropertyValue(object value, PropertyInfo property)
public static string GetPropertyValue(object value, PropertyInfo property, bool quotedString = true)
{
string convertedVal;
if (property.PropertyType == typeof(float))
convertedVal = ((float)value).ToString("0.000000####", CultureInfo.GetCultureInfo(DEFAULT_CULTURE_CODE));
else if (property.PropertyType == typeof(string))
convertedVal = $"\"{value}\"";
{
if (quotedString)
convertedVal = $"\"{value}\"";
else
convertedVal = $"{value}";
}
else
convertedVal = Convert.ToString(value, CultureInfo.GetCultureInfo(DEFAULT_CULTURE_CODE));