11using System ;
22using System . Runtime . Serialization ;
3+ using System . Security ;
34
45namespace NHibernate
56{
67 [ Serializable ]
78 public class DuplicateMappingException : MappingException
89 {
9- private readonly string type ;
10- private readonly string name ;
11-
12- /// <summary>
13- /// The type of the duplicated object
14- /// </summary>
15- public string Type
16- {
17- get { return type ; }
18- }
19-
20- /// <summary>
21- /// The name of the duplicated object
22- /// </summary>
23- public string Name
24- {
25- get { return name ; }
26- }
2710
2811 /// <summary>
2912 /// Initializes a new instance of the <see cref="MappingException"/> class.
@@ -34,8 +17,8 @@ public string Name
3417 public DuplicateMappingException ( string customMessage , string type , string name )
3518 : base ( customMessage )
3619 {
37- this . type = type ;
38- this . name = name ;
20+ Type = type ;
21+ Name = name ;
3922 }
4023
4124 /// <summary>
@@ -44,7 +27,7 @@ public DuplicateMappingException(string customMessage, string type, string name)
4427 /// <param name="name">The name of the duplicate object</param>
4528 /// <param name="type">The type of the duplicate object</param>
4629 public DuplicateMappingException ( string type , string name )
47- : this ( string . Format ( "Duplicate {0 } mapping {1}" , type , name ) , type , name )
30+ : this ( $ "Duplicate { type } mapping { name } " , type , name )
4831 {
4932 }
5033
@@ -62,6 +45,35 @@ public DuplicateMappingException(string type, string name)
6245 public DuplicateMappingException ( SerializationInfo info , StreamingContext context )
6346 : base ( info , context )
6447 {
48+ foreach ( var entry in info )
49+ {
50+ if ( entry . Name == "Type" )
51+ {
52+ Type = entry . Value ? . ToString ( ) ;
53+ }
54+ else if ( entry . Name == "Name" )
55+ {
56+ Name = entry . Value ? . ToString ( ) ;
57+ }
58+ }
6559 }
60+
61+ [ SecurityCritical ]
62+ public override void GetObjectData ( SerializationInfo info , StreamingContext context )
63+ {
64+ base . GetObjectData ( info , context ) ;
65+ info . AddValue ( "Type" , Type ) ;
66+ info . AddValue ( "Name" , Name ) ;
67+ }
68+
69+ /// <summary>
70+ /// The type of the duplicated object
71+ /// </summary>
72+ public string Type { get ; }
73+
74+ /// <summary>
75+ /// The name of the duplicated object
76+ /// </summary>
77+ public string Name { get ; }
6678 }
67- }
79+ }
0 commit comments