Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

IFormattingExtensionsToggle

interface in Unity.SmartStrings.Core.Extensions

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Lets a source stop formatter extensions from running for the placeholder it resolved.

SmartFormatter passes a FormattingInfo, which implements this interface, as the ISelectorInfo argument of ISource.TryEvaluateSelector. Cast that argument to IFormattingExtensionsToggle and set IFormattingExtensionsToggle.DisableFormattingExtensions to true when default formatting can't reasonably handle the value the source found. The source can then write the output itself with IFormattingInfo.Write, or write nothing.

Additional resources: ISource, FormattingInfo

using Unity.SmartStrings.Core.Extensions;

// Resolves {Password} to the real value, but writes a mask instead of formatting it. public class MaskedSource : ISource { public bool TryEvaluateSelector(ISelectorInfo selectorInfo) { if (selectorInfo.SelectorText != "Password") return false;

if (selectorInfo is IFormattingExtensionsToggle toggle) toggle.DisableFormattingExtensions = true;

if (selectorInfo is IFormattingInfo formattingInfo) formattingInfo.Write("********");

selectorInfo.Result = selectorInfo.CurrentValue; return true; } }

Properties

Property Description
DisableFormattingExtensions Gets or sets whether formatter extensions are skipped for the current placeholder.