private static void EventCartridgeReferenceInsertion(object sender, ReferenceInsertionEventArgs e) { if (!(e.OriginalValue is string originalString)) { return; } var lines = originalString.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); if (lines.Length == 0) { return; } e.NewValue = string.Empty; for (var i = 0; i < lines.Length - 1; i++) { e.NewValue += string.Format("{0}{1}{2}\n", NoStylePreffix, lines[i], NoStyleSuffix); } e.NewValue += string.Format("{0}{1}{2}", NoStylePreffix, lines[^ 1], NoStyleSuffix);
/// <summary> /// This is a sample of an ReferenceInsertion handler that escapes objects into /// XML strings. What matters for this handler is the topmost "escapable" or /// "not escapable" specification. /// </summary> private void EventCartridge_ReferenceInsertion(object sender, ReferenceInsertionEventArgs e) { Stack rs = e.GetCopyOfReferenceStack(); while (rs.Count > 0) { Object current = rs.Pop(); if (current is INotEscapable) { return; } if (current is IEscapable) { e.NewValue = Regex.Replace(e.OriginalValue.ToString(), "[&<>\"]", new MatchEvaluator(Escaper)); return; } } }
private static void ec_ReferenceInsertion(object sender, ReferenceInsertionEventArgs e) { if (e.OriginalValue == null) { return; } var s = e.GetCopyOfReferenceStack(); while (s.Count > 0) { var current = s.Pop(); if (!(current is IEscapable)) { continue; } e.NewValue = XmlEncoder.Encode(Convert.ToString(e.OriginalValue)); return; } }
private static void EventCartridgeReferenceInsertion(object sender, ReferenceInsertionEventArgs e) { var originalString = e.OriginalValue as string; if (originalString == null) { return; } var lines = originalString.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); if (lines.Length == 0) { return; } e.NewValue = string.Empty; for (var i = 0; i < lines.Length - 1; i++) { e.NewValue += string.Format("nostyle{0}/nostyle\n", lines[i]); } e.NewValue += string.Format("nostyle{0}/nostyle", lines[lines.Length - 1]); }
/// <summary> /// This is a sample of an ReferenceInsertion handler that escapes objects into /// XML strings. What matters for this handler is the topmost "escapable" or /// "not escapable" specification. /// </summary> private void EventCartridge_ReferenceInsertion(object sender, ReferenceInsertionEventArgs e) { Stack rs = e.GetCopyOfReferenceStack(); while(rs.Count > 0) { Object current = rs.Pop(); if (current is INotEscapable) return; if (current is IEscapable) { e.NewValue = Regex.Replace(e.OriginalValue.ToString(), "[&<>\"]", new MatchEvaluator(Escaper)); return; } } if (e.RootString == "$multipleItems") { e.NewValue = new[] {"Item 1", "Item 2"}; } else if (e.RootString == "$singleItem") { e.NewValue = "New single item"; } }