Repository navigation
Expand file tree
/
Copy pathIncWebException.cs
More file actions
68 lines (50 loc) · 1.71 KB
/
Copy pathIncWebException.cs
File metadata and controls
68 lines (50 loc) · 1.71 KB
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
namespace Incoding
{
#region << Using >>
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Incoding.Extensions;
#endregion
public class IncWebException : Exception
{
#region Constructors
[Obsolete("Please use factory method IncWebException.For")]
public IncWebException(string message) : base(message)
{
Errors = new Dictionary<string, List<string>>();
}
#endregion
#region Factory constructors
public static IncWebException For<TModel>(Expression<Func<TModel, object>> property, string message)
{
return new IncWebException(message).Also(property, message);
}
public static IncWebException ForServer(string message)
{
return new IncWebException(message).Also("Server", message);
}
public static IncWebException For(string property, string message)
{
return new IncWebException(message).Also(property, message);
}
#endregion
#region Properties
public Dictionary<string, List<string>> Errors { get; set; }
#endregion
#region Api Methods
public IncWebException Also<TModel>(Expression<Func<TModel, object>> property, string message)
{
return Also(property.GetMemberNameAsHtmlId(), message);
}
public IncWebException Also(string property, string message)
{
if (Errors.ContainsKey(property))
Errors[property].Add(message);
else
Errors.Add(property, new List<string> { message });
return this;
}
#endregion
}
}