forked from nhibernate/nhibernate-core
/
InvalidProxyTypeException.cs
54 lines (47 loc) · 1.44 KB
/
InvalidProxyTypeException.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
using System;
using System.Collections;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;
using System.Collections.Generic;
namespace NHibernate
{
/// <summary>
/// Thrown when an invalid type is specified as a proxy for a class.
/// The exception is also thrown when a class is specified as lazy,
/// but cannot be used as a proxy for itself.
/// </summary>
[Serializable]
public class InvalidProxyTypeException : MappingException
{
public InvalidProxyTypeException(ICollection<string> errors)
: base(FormatMessage(errors))
{
Errors = errors;
}
public ICollection<string> Errors { get; private set; }
private static string FormatMessage(IEnumerable<string> errors)
{
var result = new StringBuilder("The following types may not be used as proxies:");
foreach (string error in errors)
{
result.Append('\n').Append(error);
}
return result.ToString();
}
#region Serialization
public InvalidProxyTypeException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Errors = (ICollection<string>)info.GetValue("errors", typeof(ICollection));
}
[SecurityPermission(SecurityAction.LinkDemand,
Flags=SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("errors", Errors, typeof(ICollection));
}
#endregion
}
}