示例#1
0
		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;
			}
		}
		/// <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;
				}
			}
		}
        /// <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 string[] {"Item 1", "Item 2"};
            }
            else if (e.RootString == "$singleItem")
            {
                e.NewValue = "New single item";
            }
        }