Exemplo n.º 1
0
		/// <summary>
		/// Called during Velocity merge before a reference value will
		/// be inserted into the output stream.
		/// </summary>
		/// <param name="referenceStack">the stack of objects used to reach this reference</param>
		/// <param name="reference">reference from template about to be inserted</param>
		/// <param name="value"> value about to be inserted (after toString() )</param>
		/// <returns>
		/// Object on which toString() should be called for output.
		/// </returns>
		internal Object ReferenceInsert(Stack referenceStack, String reference, Object value)
		{
			if (ReferenceInsertion != null)
			{
				ReferenceInsertionEventArgs args = new ReferenceInsertionEventArgs(referenceStack, reference, value);
				ReferenceInsertion(this, args);
				value = args.NewValue;
			}

			return value;
		}
 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("{0}{1}{2}\n", NoStylePreffix, lines[i], NoStyleSuffix);
     }
     e.NewValue += string.Format("{0}{1}{2}", NoStylePreffix, lines[lines.Length - 1], NoStyleSuffix);
 }
Exemplo n.º 3
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;
			}
		}
        void OnReferenceInsertion(object sender, ReferenceInsertionEventArgs e)
        {
            Debug.Assert(sender != null);
            Debug.Assert(e != null);

            if (e.OriginalValue != null)
            {
                this.DoFilter(e);
            }
            else
            {
                e.NewValue = string.Empty;
            }
        }
        private void DoFilter(ReferenceInsertionEventArgs e)
        {
            Debug.Assert(e != null);

            var t = e.OriginalValue.GetType();
            IRenderFilter filter = null;
            var hasFilter = this.filters.TryGetValue(t, out filter);
            if (hasFilter)
            {
                Debug.Assert(filter != null);
                e.NewValue = filter.Filter(e.OriginalValue);
            }
        }
		/// <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";
            }
        }