Beispiel #1
0
 /// <summary>
 /// Creates and initializes the rule.
 /// </summary>
 /// <param name="handler">The address of the method implementing the rule.</param>
 /// <param name="args">A RuleArgs object.</param>
 public RuleMethod(RuleHandler handler, RuleArgs args)
 {
     _handler  = handler;
     _args     = args;
     _ruleName = string.Format(@"rule://{0}/{1}/{2}",
                               Uri.EscapeDataString(_handler.Method.DeclaringType.FullName),
                               _handler.Method.Name,
                               _args.ToString());
 }
Beispiel #2
0
 /// <summary>
 /// Creates and initializes the rule.
 /// </summary>
 /// <param name="handler">The address of the method implementing the rule.</param>
 /// <param name="args">A RuleArgs object.</param>
 /// <param name="severity">Severity of the rule.</param>
 public AsyncRuleMethod(AsyncRuleHandler handler, AsyncRuleArgs args, RuleSeverity severity)
 {
     _handler  = handler;
     _args     = args;
     _severity = severity;
     _ruleName = string.Format(@"rule://{0}/{1}/{2}",
                               Uri.EscapeDataString(_handler.Method.DeclaringType.FullName),
                               _handler.Method.Name,
                               _args.Properties[0].Name);
 }
        /// <summary>
        /// Return a string representation of
        /// the object using the rule:// URI
        /// format.
        /// </summary>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(base.ToString());
            if (_decorations.Count > 0)
            {
                sb.Append("?");
                bool first = true;
                foreach (System.Collections.Generic.KeyValuePair <string, object> item in _decorations)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append("&");
                    }
                    if (item.Key != null)
                    {
                        var    itemString = Uri.EscapeDataString(item.Key);
                        string valueString;
                        if (item.Value == null)
                        {
                            valueString = string.Empty;
                        }
                        else
                        {
                            valueString = Uri.EscapeDataString(item.Value.ToString());
                        }
                        sb.AppendFormat("{0}={1}", itemString, valueString);
                    }
                }
            }
            return(sb.ToString());
        }