// ------------------------------------------------------------------ // 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)); } }
/// <summary> /// Produces a string that describes a source object: /// e.g. element in a Binding Path, DataItem in BindingExpression, ContextElement /// </summary> /// <param name="traceBuilder">description will be appended to this builder</param> /// <param name="o">a source object (e.g. element in a Binding Path, DataItem in BindingExpression, ContextElement)</param> /// <returns>a string that describes the object</returns> static public void DescribeSourceObject(AvTraceBuilder traceBuilder, object o) { if (o == null) { traceBuilder.Append("null"); } else { FrameworkElement fe = o as FrameworkElement; if (fe != null) { traceBuilder.AppendFormat("'{0}' (Name='{1}')", fe.GetType().Name, fe.Name); } else { traceBuilder.AppendFormat("'{0}' (HashCode={1})", o.GetType().Name, o.GetHashCode()); } } }
/// <summary> /// Produces a string that describes TargetElement and TargetProperty /// </summary> /// <param name="traceBuilder">description will be appended to this builder</param> /// <param name="targetElement">TargetElement</param> /// <param name="targetProperty">TargetProperty</param> /// <returns>a string that describes TargetElement and TargetProperty</returns> static public void DescribeTarget(AvTraceBuilder traceBuilder, DependencyObject targetElement, DependencyProperty targetProperty) { if (targetElement != null) { traceBuilder.Append("target element is "); DescribeSourceObject(traceBuilder, targetElement); if (targetProperty != null) { traceBuilder.Append("; "); } } if (targetProperty != null) { traceBuilder.AppendFormat("target property is '{0}' (type '{1}')", targetProperty.Name, targetProperty.PropertyType.Name); } }
// ------------------------------------------------------------------ // 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)); } }