This commit is contained in:
2020-02-27 16:25:21 +00:00
parent fc604e1745
commit f1a1ca69d9
3 changed files with 38 additions and 29 deletions

View File

@@ -90,30 +90,30 @@ namespace AyaNova.Util
}
/// <summary>
/// Make a unique but duplicate object name of desired length
/// (Used by Duplicate object function)
/// </summary>
/// <param name="s"></param>
/// <param name="maxLength"></param>
/// <returns></returns>
public static string NameUniquify(string s, int maxLength)
{
//Unique string
string unique = " - " + DateUtil.SortableShortCurrentDateTimeValue;
string ret = s + unique;
var diff = maxLength - ret.Length;
if (diff < 0)
{
if (unique.Length >= maxLength)
{
throw new System.ArgumentOutOfRangeException("StringUtil::nameUniquify - maxlength> unique value, source field too short for this function?");
}
ret = s.Substring(0, Math.Abs(diff)) + unique;
}
// /// <summary>
// /// Make a unique but duplicate object name of desired length
// /// (Used by Duplicate object function)
// /// </summary>
// /// <param name="s"></param>
// /// <param name="maxLength"></param>
// /// <returns></returns>
// public static string NameUniquify(string s, int maxLength)
// {
// //Unique string
// string unique = " - " + DateUtil.SortableShortCurrentDateTimeValue;
// string ret = s + unique;
// var diff = maxLength - ret.Length;
// if (diff < 0)
// {
// if (unique.Length >= maxLength)
// {
// throw new System.ArgumentOutOfRangeException("StringUtil::nameUniquify - maxlength> unique value, source field too short for this function?");
// }
// ret = s.Substring(0, Math.Abs(diff)) + unique;
// }
return ret;
}
// return ret;
// }
//Used to ensure a unique name generated by appending -nnn is within length requirements by splitting and chopping part of text to keep name