summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Diagnostics/AssertFilter.cs
blob: 7c861de58ec4e00e1b9f62e61bdf735834bdc0c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.



using System;
using System.Runtime.Versioning;

namespace System.Diagnostics
{
    // A Filter is used to decide whether an assert failure 
    // should terminate the program (or invoke the debugger).  
    // Typically this is done by popping up a dialog & asking the user.
    // 
    // The default filter brings up a simple Win32 dialog with 3 buttons.

    [Serializable]
    abstract internal class AssertFilter
    {
        // Called when an assert fails.  This should be overridden with logic which
        // determines whether the program should terminate or not.  Typically this
        // is done by asking the user.
        //
        // The windowTitle can be null.
        abstract public AssertFilters AssertFailure(String condition, String message,
                                  StackTrace location, StackTrace.TraceFormat stackTraceFormat, String windowTitle);
    }
    // No data, does not need to be marked with the serializable attribute
    internal class DefaultFilter : AssertFilter
    {
        internal DefaultFilter()
        {
        }

        public override AssertFilters AssertFailure(String condition, String message,
                                  StackTrace location, StackTrace.TraceFormat stackTraceFormat,
                                  String windowTitle)

        {
            return (AssertFilters)Assert.ShowDefaultAssertDialog(condition, message, location.ToString(stackTraceFormat), windowTitle);
        }
    }
}