Skip to content

Instantly share code, notes, and snippets.

@jagregory
Created August 18, 2010 20:49
Show Gist options
  • Save jagregory/536144 to your computer and use it in GitHub Desktop.
Save jagregory/536144 to your computer and use it in GitHub Desktop.
// example:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
BindingErrors.Throw();
// app gubbins here
}
}
// code:
public static class BindingErrors
{
public static void Throw()
{
PresentationTraceSources.DataBindingSource.Listeners.Add(new BindingErrorListener
{
TraceOutputOptions = TraceOptions.None
});
PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.Error;
}
}
public class BindingErrorListener : DefaultTraceListener
{
readonly StringBuilder builder = new StringBuilder();
public override void Write(string message)
{
builder.Append(message);
}
public override void WriteLine(string message)
{
builder.Append(message);
var fullMessage = builder.ToString();
builder.Length = 0;
throw new BindingException(fullMessage);
}
}
public class BindingException : Exception
{
public BindingException(string message)
: base(message)
{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment