File: RegexMatchTimeoutException.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (168 lines) | stat: -rw-r--r-- 5,918 bytes parent folder | download | duplicates (7)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
///------------------------------------------------------------------------------
/// <copyright file="RegexMatchTimeoutException.cs" company="Microsoft">
///     Copyright (c) Microsoft Corporation.  All rights reserved.
/// </copyright>                               
///
/// <owner>gpaperin</owner>
///------------------------------------------------------------------------------

using System;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;


namespace System.Text.RegularExpressions {

/// <summary>
/// This is the exception that is thrown when a RegEx matching timeout occurs.
/// </summary>

#if SILVERLIGHT
#if FEATURE_NETCORE
public
#else
internal 
#endif
class RegexMatchTimeoutException : TimeoutException {
#else
[Serializable]
public class RegexMatchTimeoutException : TimeoutException, ISerializable {
#endif


    private string regexInput = null;

    private string regexPattern = null;

    private TimeSpan matchTimeout = TimeSpan.FromTicks(-1);


    /// <summary>
    /// This is the preferred constructor to use.
    /// The other constructors are provided for compliance to Fx design guidelines.
    /// </summary>
    /// <param name="regexInput">Matching timeout occured during mathing within the specified input.</param>
    /// <param name="regexPattern">Matching timeout occured during mathing to the specified pattern.</param>
    /// <param name="matchTimeout">Matching timeout occured becasue matching took longer than the specified timeout.</param>
    public RegexMatchTimeoutException(string regexInput, string regexPattern, TimeSpan matchTimeout) :
        base(SR.GetString(SR.RegexMatchTimeoutException_Occurred)) {
        Init(regexInput, regexPattern, matchTimeout);
    }


    /// <summary>
    /// This constructor is provided in compliance with common NetFx design patterns;
    /// developers should prefer using the constructor
    /// <code>public RegexMatchTimeoutException(string input, string pattern, TimeSpan matchTimeout)</code>.
    /// </summary>    
    public RegexMatchTimeoutException()
        : base() {
        Init();
    }


    /// <summary>
    /// This constructor is provided in compliance with common NetFx design patterns;
    /// developers should prefer using the constructor
    /// <code>public RegexMatchTimeoutException(string input, string pattern, TimeSpan matchTimeout)</code>.
    /// </summary>
    /// <param name="message">The error message that explains the reason for the exception.</param>
    public RegexMatchTimeoutException(string message)
        : base(message) {
        Init();
    }


    /// <summary>
    /// This constructor is provided in compliance with common NetFx design patterns;
    /// developers should prefer using the constructor
    /// <code>public RegexMatchTimeoutException(string input, string pattern, TimeSpan matchTimeout)</code>.
    /// </summary>
    /// <param name="message">The error message that explains the reason for the exception.</param>
    /// <param name="inner">The exception that is the cause of the current exception, or a <code>null</code>.</param>
    public RegexMatchTimeoutException(string message, Exception inner)
        : base(message, inner) {
        Init();
    }


    #if !SILVERLIGHT
    /// <summary>
    /// Initializes a new RegexMatchTimeoutException with serialized data.
    /// </summary>
    /// <param name="info">The SerializationInfo  that holds the serialized object data about the exception being thrown.</param>
    /// <param name="context">The StreamingContext  that contains contextual information about the source or destination.</param>
    [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter=true)]
    protected RegexMatchTimeoutException(SerializationInfo info, StreamingContext context) :
        base(info, context) {

        string input = info.GetString("regexInput");
        string pattern = info.GetString("regexPattern");
        TimeSpan timeout = TimeSpan.FromTicks(info.GetInt64("timeoutTicks"));
        Init(input, pattern, timeout);
    }
        
    [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter=true)]
    void ISerializable.GetObjectData(SerializationInfo si, StreamingContext context) {
        base.GetObjectData(si, context);
        si.AddValue("regexInput", this.regexInput);
        si.AddValue("regexPattern", this.regexPattern);
        si.AddValue("timeoutTicks", this.matchTimeout.Ticks);
    }
    #endif // !SILVERLIGHT

    private void Init() {
        Init("", "", TimeSpan.FromTicks(-1));
    }

    private void Init(string input, string pattern, TimeSpan timeout) {
        this.regexInput = input;
        this.regexPattern = pattern;
        this.matchTimeout = timeout;
    }

    #if SILVERLIGHT && !FEATURE_NETCORE
    internal string Pattern {
    #else
    public string Pattern {
    #endif
    #if SILVERLIGHT
        [SecurityCritical]
    #else  // SILVERLIGHT
        [PermissionSet(SecurityAction.LinkDemand, Unrestricted=true)]
    #endif  // SILVERLIGHT
        get { return regexPattern; }
    }

    #if SILVERLIGHT && !FEATURE_NETCORE
    internal string Input {
    #else
    public string Input {
    #endif
    #if SILVERLIGHT
        [SecurityCritical]
    #else  // SILVERLIGHT
        [PermissionSet(SecurityAction.LinkDemand, Unrestricted=true)]
    #endif  // SILVERLIGHT
        get { return regexInput; }
    }

    #if SILVERLIGHT && !FEATURE_NETCORE
    internal TimeSpan MatchTimeout {
    #else
    public TimeSpan MatchTimeout {
    #endif
    #if SILVERLIGHT
        [SecurityCritical]
    #else  // SILVERLIGHT
        [PermissionSet(SecurityAction.LinkDemand, Unrestricted=true)]
    #endif  // SILVERLIGHT
        get { return matchTimeout; }
    }
} // public class RegexMatchTimeoutException


} // namespace System.Text.RegularExpressions

// file RegexMatchTimeoutException.cs