///------------------------------------------------------------------------------
///
/// Copyright (c) Microsoft Corporation. All rights reserved.
///
///
/// gpaperin
///------------------------------------------------------------------------------
using System;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
namespace System.Text.RegularExpressions {
///
/// This is the exception that is thrown when a RegEx matching timeout occurs.
///
#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);
///
/// This is the preferred constructor to use.
/// The other constructors are provided for compliance to Fx design guidelines.
///
/// Matching timeout occured during mathing within the specified input.
/// Matching timeout occured during mathing to the specified pattern.
/// Matching timeout occured becasue matching took longer than the specified timeout.
public RegexMatchTimeoutException(string regexInput, string regexPattern, TimeSpan matchTimeout) :
base(SR.GetString(SR.RegexMatchTimeoutException_Occurred)) {
Init(regexInput, regexPattern, matchTimeout);
}
///
/// This constructor is provided in compliance with common NetFx design patterns;
/// developers should prefer using the constructor
/// public RegexMatchTimeoutException(string input, string pattern, TimeSpan matchTimeout)
.
///
public RegexMatchTimeoutException()
: base() {
Init();
}
///
/// This constructor is provided in compliance with common NetFx design patterns;
/// developers should prefer using the constructor
/// public RegexMatchTimeoutException(string input, string pattern, TimeSpan matchTimeout)
.
///
/// The error message that explains the reason for the exception.
public RegexMatchTimeoutException(string message)
: base(message) {
Init();
}
///
/// This constructor is provided in compliance with common NetFx design patterns;
/// developers should prefer using the constructor
/// public RegexMatchTimeoutException(string input, string pattern, TimeSpan matchTimeout)
.
///
/// The error message that explains the reason for the exception.
/// The exception that is the cause of the current exception, or a null
.
public RegexMatchTimeoutException(string message, Exception inner)
: base(message, inner) {
Init();
}
#if !SILVERLIGHT
///
/// Initializes a new RegexMatchTimeoutException with serialized data.
///
/// The SerializationInfo that holds the serialized object data about the exception being thrown.
/// The StreamingContext that contains contextual information about the source or destination.
[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