Workaround for nested ZString.Format calls
jchowgithub opened this issue · 1 comments
Hi, let's say we have a class named Teammember that has this overridden ToString() code:
public override string ToString() { return ZString.Format("{0}:{1}:{2}",m_currentTeam,m_currentHealth,m_currentStamina);
but m_currentTeam is itself an instance of class Team with its own overridden ToString()
public override string ToString() { return ZString.Format("{0}:{1}:{2}",m_name,m_score,m_members);
If we call Teammember.ToString(), it'll end up calling ZString.Format recursively and cause an exception:
NestedStringBuilderCreationException: A nested call with notNested: true
, or Either You forgot to call Utf16ValueStringBuilder.Dispose() of in the past.
because there's no way to control the nesting behavior of the StringBuilder that ZString.Format uses internally.
We'd like to continue to be able to override ToString(), so has anyone come up with a clean pattern to use ZString and nested ToString() calls? The other way we can do it is to create the StringBuilder instance manually and call Append/AppendFormat but it would require making a lot of changes to our codebase.
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.