Debian Codegraph @

mcs/class/referencesource/System/regex/system/text/regularexpressions/RegexMatchTimeoutException.cs

raw
1 ///------------------------------------------------------------------------------
2 /// <copyright file="RegexMatchTimeoutException.cs" company="Microsoft">
3 /// Copyright (c) Microsoft Corporation. All rights reserved.
4 /// </copyright>
5 ///
6 /// <owner>gpaperin</owner>
7 ///------------------------------------------------------------------------------
8
9 using System;
10 using System.Runtime.Serialization;
11 using System.Security;
12 using System.Security.Permissions;
13
14
15 namespace System.Text.RegularExpressions {
16
17 /// <summary>
18 /// This is the exception that is thrown when a RegEx matching timeout occurs.
19 /// </summary>
20
21 #if SILVERLIGHT
22 #if FEATURE_NETCORE
23 public
24 #else
25 internal
26 #endif
27 class RegexMatchTimeoutException : TimeoutException {
28 #else
29 [Serializable]
30 public class RegexMatchTimeoutException : TimeoutException, ISerializable {
31 #endif
32
33
34 private string regexInput = null;
35
36 private string regexPattern = null;
37
38 private TimeSpan matchTimeout = TimeSpan.FromTicks(-1);
39
40
41 /// <summary>
42 /// This is the preferred constructor to use.
43 /// The other constructors are provided for compliance to Fx design guidelines.
44 /// </summary>
45 /// <param name="regexInput">Matching timeout occured during mathing within the specified input.</param>
46 /// <param name="regexPattern">Matching timeout occured during mathing to the specified pattern.</param>
47 /// <param name="matchTimeout">Matching timeout occured becasue matching took longer than the specified timeout.</param>
48 public RegexMatchTimeoutException(string regexInput, string regexPattern, TimeSpan matchTimeout) :
49 base(SR.GetString(SR.RegexMatchTimeoutException_Occurred)) {
50 Init(regexInput, regexPattern, matchTimeout);
51 }
52
53
54 /// <summary>
55 /// This constructor is provided in compliance with common NetFx design patterns;
56 /// developers should prefer using the constructor
57 /// <code>public RegexMatchTimeoutException(string input, string pattern, TimeSpan matchTimeout)</code>.
58 /// </summary>
59 public RegexMatchTimeoutException()
60 : base() {
61 Init();
62 }
63
64
65 /// <summary>
66 /// This constructor is provided in compliance with common NetFx design patterns;
67 /// developers should prefer using the constructor
68 /// <code>public RegexMatchTimeoutException(string input, string pattern, TimeSpan matchTimeout)</code>.
69 /// </summary>
70 /// <param name="message">The error message that explains the reason for the exception.</param>
71 public RegexMatchTimeoutException(string message)
72 : base(message) {
73 Init();
74 }
75
76
77 /// <summary>
78 /// This constructor is provided in compliance with common NetFx design patterns;
79 /// developers should prefer using the constructor
80 /// <code>public RegexMatchTimeoutException(string input, string pattern, TimeSpan matchTimeout)</code>.
81 /// </summary>
82 /// <param name="message">The error message that explains the reason for the exception.</param>
83 /// <param name="inner">The exception that is the cause of the current exception, or a <code>null</code>.</param>
84 public RegexMatchTimeoutException(string message, Exception inner)
85 : base(message, inner) {
86 Init();
87 }
88
89
90 #if !SILVERLIGHT
91 /// <summary>
92 /// Initializes a new RegexMatchTimeoutException with serialized data.
93 /// </summary>
94 /// <param name="info">The SerializationInfo that holds the serialized object data about the exception being thrown.</param>
95 /// <param name="context">The StreamingContext that contains contextual information about the source or destination.</param>
96 [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter=true)]
97 protected RegexMatchTimeoutException(SerializationInfo info, StreamingContext context) :
98 base(info, context) {
99
100 string input = info.GetString("regexInput");
101 string pattern = info.GetString("regexPattern");
102 TimeSpan timeout = TimeSpan.FromTicks(info.GetInt64("timeoutTicks"));
103 Init(input, pattern, timeout);
104 }
105
106 [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter=true)]
107 void ISerializable.GetObjectData(SerializationInfo si, StreamingContext context) {
108 base.GetObjectData(si, context);
109 si.AddValue("regexInput", this.regexInput);
110 si.AddValue("regexPattern", this.regexPattern);
111 si.AddValue("timeoutTicks", this.matchTimeout.Ticks);
112 }
113 #endif // !SILVERLIGHT
114
115 private void Init() {
116 Init("", "", TimeSpan.FromTicks(-1));
117 }
118
119 private void Init(string input, string pattern, TimeSpan timeout) {
120 this.regexInput = input;
121 this.regexPattern = pattern;
122 this.matchTimeout = timeout;
123 }
124
125 #if SILVERLIGHT && !FEATURE_NETCORE
126 internal string Pattern {
127 #else
128 public string Pattern {
129 #endif
130 #if SILVERLIGHT
131 [SecurityCritical]
132 #else // SILVERLIGHT
133 [PermissionSet(SecurityAction.LinkDemand, Unrestricted=true)]
134 #endif // SILVERLIGHT
135 get { return regexPattern; }
136 }
137
138 #if SILVERLIGHT && !FEATURE_NETCORE
139 internal string Input {
140 #else
141 public string Input {
142 #endif
143 #if SILVERLIGHT
144 [SecurityCritical]
145 #else // SILVERLIGHT
146 [PermissionSet(SecurityAction.LinkDemand, Unrestricted=true)]
147 #endif // SILVERLIGHT
148 get { return regexInput; }
149 }
150
151 #if SILVERLIGHT && !FEATURE_NETCORE
152 internal TimeSpan MatchTimeout {
153 #else
154 public TimeSpan MatchTimeout {
155 #endif
156 #if SILVERLIGHT
157 [SecurityCritical]
158 #else // SILVERLIGHT
159 [PermissionSet(SecurityAction.LinkDemand, Unrestricted=true)]
160 #endif // SILVERLIGHT
161 get { return matchTimeout; }
162 }
163 } // public class RegexMatchTimeoutException
164
165
166 } // namespace System.Text.RegularExpressions
167
168 // file RegexMatchTimeoutException.cs