static public string IdentifyException(Exception ex) { if (ex == null) { return("<no error>"); } return(Format("{0} ({1})", ex.GetType().Name, AvTrace.AntiFormat(ex.Message))); }
public void AppendFormat(string message, params object[] args) { object[] argstrs = new object[args.Length]; for (int i = 0; i < args.Length; ++i) { string s = args[i] as string; argstrs[i] = (s != null) ? s : AvTrace.ToStringHelper(args[i]); } _sb.AppendFormat(CultureInfo.InvariantCulture, message, argstrs); }
// ------------------------------------------------------------------ // Helper functions for message string construction // ------------------------------------------------------------------ /// <summary> /// Construct a string that describes data and debugging information about the object. /// A title is appended in front if provided. /// If object o is not a recognized object, it will be ToString()'ed. /// </summary> /// <param name="traceBuilder">description will be appended to this builder</param> /// <param name="o">object to be described; /// currently recognized types: BindingExpression, Binding, DependencyObject, Exception</param> /// <returns>a string that describes the object</returns> static public void Describe(AvTraceBuilder traceBuilder, object o) { if (o == null) { traceBuilder.Append("null"); } else if (o is BindingExpression) { BindingExpression bindingExpr = o as BindingExpression; Describe(traceBuilder, bindingExpr.ParentBinding); traceBuilder.Append("; DataItem="); DescribeSourceObject(traceBuilder, bindingExpr.DataItem); traceBuilder.Append("; "); DescribeTarget(traceBuilder, bindingExpr.TargetElement, bindingExpr.TargetProperty); } else if (o is Binding) { Binding binding = o as Binding; if (binding.Path != null) { traceBuilder.AppendFormat("Path={0}", binding.Path.Path); } else if (binding.XPath != null) { traceBuilder.AppendFormat("XPath={0}", binding.XPath); } else { traceBuilder.Append("(no path)"); } } else if (o is BindingExpressionBase) { BindingExpressionBase beb = o as BindingExpressionBase; DescribeTarget(traceBuilder, beb.TargetElement, beb.TargetProperty); } else if (o is DependencyObject) { DescribeSourceObject(traceBuilder, o); } else { traceBuilder.AppendFormat("'{0}'", AvTrace.ToStringHelper(o)); } }
static public string Identify(object o) { if (o == null) { return("<null>"); } Type type = o.GetType(); if (type.IsPrimitive || type.IsEnum) { return(Format("'{0}'", o)); } string s = o as String; if (s != null) { return(Format("'{0}'", AvTrace.AntiFormat(s))); } NamedObject n = o as NamedObject; if (n != null) { return(AvTrace.AntiFormat(n.ToString())); } ICollection ic = o as ICollection; if (ic != null) { return(Format("{0} (hash={1} Count={2})", type.Name, AvTrace.GetHashCodeHelper(o), ic.Count)); } return(Format("{0} (hash={1})", type.Name, AvTrace.GetHashCodeHelper(o))); }
public void AppendFormat(string message, string arg1, string arg2) { _sb.AppendFormat(CultureInfo.InvariantCulture, message, new object[] { AvTrace.AntiFormat(arg1), AvTrace.AntiFormat(arg2) }); }
public void AppendFormat(string message, object arg1, object arg2) { _sb.AppendFormat(CultureInfo.InvariantCulture, message, new object[] { AvTrace.ToStringHelper(arg1), AvTrace.ToStringHelper(arg2) }); }