-
Notifications
You must be signed in to change notification settings - Fork 935
/
Copy pathDuplicateMappingException.cs
78 lines (72 loc) · 2.18 KB
/
DuplicateMappingException.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
using System;
using System.Runtime.Serialization;
using System.Security;
namespace NHibernate
{
[Serializable]
public class DuplicateMappingException : MappingException
{
/// <summary>
/// Initializes a new instance of the <see cref="MappingException"/> class.
/// </summary>
/// <param name="customMessage">The message that describes the error. </param>
/// <param name="name">The name of the duplicate object</param>
/// <param name="type">The type of the duplicate object</param>
public DuplicateMappingException(string customMessage, string type, string name)
: base(customMessage)
{
Type = type;
Name = name;
}
/// <summary>
/// Initializes a new instance of the <see cref="MappingException"/> class.
/// </summary>
/// <param name="name">The name of the duplicate object</param>
/// <param name="type">The type of the duplicate object</param>
public DuplicateMappingException(string type, string name)
: this($"Duplicate {type} mapping {name}", type, name)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="MappingException"/> class
/// with serialized data.
/// </summary>
/// <param name="info">
/// The <see cref="SerializationInfo"/> that holds the serialized object
/// data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="StreamingContext"/> that contains contextual information about the source or destination.
/// </param>
public DuplicateMappingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
foreach (var entry in info)
{
if (entry.Name == "Type")
{
Type = entry.Value?.ToString();
}
else if (entry.Name == "Name")
{
Name = entry.Value?.ToString();
}
}
}
[SecurityCritical]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("Type", Type);
info.AddValue("Name", Name);
}
/// <summary>
/// The type of the duplicated object
/// </summary>
public string Type { get; }
/// <summary>
/// The name of the duplicated object
/// </summary>
public string Name { get; }
}
}