This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseException{T}.cs
123 lines (109 loc) · 5.19 KB
/
BaseException{T}.cs
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
// -----------------------------------------------------------------------
// <copyright file="BaseException{T}.cs" company="-">
// Copyright (c) 2014 Eser Ozvataf ([email protected]). All rights reserved.
// Web: http://eser.ozvataf.com/ GitHub: http://github.com/larukedi
// </copyright>
// <author>Eser Ozvataf ([email protected])</author>
// -----------------------------------------------------------------------
//// This program is free software: you can redistribute it and/or modify
//// it under the terms of the GNU General Public License as published by
//// the Free Software Foundation, either version 3 of the License, or
//// (at your option) any later version.
////
//// This program is distributed in the hope that it will be useful,
//// but WITHOUT ANY WARRANTY; without even the implied warranty of
//// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//// GNU General Public License for more details.
////
//// You should have received a copy of the GNU General Public License
//// along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace Tasslehoff.Library
{
using System;
using System.Runtime.Serialization;
/// <summary>
/// BaseExceptionGeneric class.
/// </summary>
/// <typeparam name="T">Any type</typeparam>
/// <remarks>
/// You can use BaseException<dynamic> to use dynamic parameters.
/// </remarks>
[Serializable]
public abstract class BaseException<T> : BaseException
{
// fields
/// <summary>
/// The exception object
/// </summary>
[DataMember(Name = "ExceptionObject")]
private T exceptionObject;
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="BaseException{T}"/> class.
/// </summary>
/// <param name="exceptionObject">The exception object</param>
public BaseException(T exceptionObject) : base()
{
this.exceptionObject = exceptionObject;
}
/// <summary>
/// Initializes a new instance of the <see cref="BaseException{T}"/> class.
/// </summary>
/// <param name="exceptionObject">The exception object</param>
/// <param name="message">The message</param>
public BaseException(T exceptionObject, string message) : base(message)
{
this.exceptionObject = exceptionObject;
}
/// <summary>
/// Initializes a new instance of the <see cref="BaseException{T}"/> class.
/// </summary>
/// <param name="exceptionObject">The exception object</param>
/// <param name="message">The message</param>
/// <param name="innerException">The inner exception</param>
public BaseException(T exceptionObject, string message, Exception innerException) : base(message, innerException)
{
this.exceptionObject = exceptionObject;
}
/// <summary>
/// Initializes a new instance of the <see cref="BaseException{T}"/> class.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination</param>
protected BaseException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
this.exceptionObject = (T)info.GetValue("exceptionObject", typeof(T));
}
// properties
/// <summary>
/// Gets the exception object.
/// </summary>
/// <value>
/// The exception object.
/// </value>
[IgnoreDataMember]
public T ExceptionObject
{
get
{
return this.exceptionObject;
}
}
// methods
/// <summary>
/// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> with information about the exception.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination</param>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter" />
/// </PermissionSet>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("exceptionObject", this.exceptionObject);
}
}
}