0
|
1 using System;
|
|
2
|
|
3 namespace BLToolkit.Patterns
|
|
4 {
|
|
5 [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Property)]
|
|
6 public sealed class MustImplementAttribute : Attribute
|
|
7 {
|
|
8 public MustImplementAttribute(bool implement, bool throwException, string exceptionMessage)
|
|
9 {
|
|
10 _implement = implement;
|
|
11 _throwException = throwException;
|
|
12 _exceptionMessage = exceptionMessage;
|
|
13 }
|
|
14
|
|
15 public MustImplementAttribute(bool implement, bool throwException)
|
|
16 : this(implement, throwException, null)
|
|
17 {
|
|
18 }
|
|
19
|
|
20 public MustImplementAttribute(bool implement, string exceptionMessage)
|
|
21 : this(implement, true, exceptionMessage)
|
|
22 {
|
|
23 }
|
|
24
|
|
25 public MustImplementAttribute(bool implement)
|
|
26 : this(implement, true, null)
|
|
27 {
|
|
28 }
|
|
29
|
|
30 public MustImplementAttribute()
|
|
31 : this(true, true, null)
|
|
32 {
|
|
33 }
|
|
34
|
|
35 private readonly bool _implement;
|
|
36 public bool Implement
|
|
37 {
|
|
38 get { return _implement; }
|
|
39 }
|
|
40
|
|
41 private bool _throwException;
|
|
42 public bool ThrowException
|
|
43 {
|
|
44 get { return _throwException; }
|
|
45 set { _throwException = value; }
|
|
46 }
|
|
47
|
|
48 private string _exceptionMessage;
|
|
49 public string ExceptionMessage
|
|
50 {
|
|
51 get { return _exceptionMessage; }
|
|
52 set { _exceptionMessage = value; }
|
|
53 }
|
|
54
|
|
55 /// <summary>
|
|
56 /// All methods are optional and throws <see cref="NotImplementedException"/> at run tune.
|
|
57 /// </summary>
|
|
58 public static readonly MustImplementAttribute Default = new MustImplementAttribute(false, true, null);
|
|
59
|
|
60 /// <summary>
|
|
61 /// All methods are optional and does nothing at run tune.
|
|
62 /// Return value and all output parameters will be set to appropriate default values.
|
|
63 /// </summary>
|
|
64 public static readonly MustImplementAttribute Aggregate = new MustImplementAttribute(false, false, null);
|
|
65 }
|
|
66 }
|