Mercurial > pub > bltoolkit
comparison Source/TypeBuilder/Builders/FakeParameterInfo.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 using System; | |
2 using System.Collections; | |
3 using System.Reflection; | |
4 | |
5 namespace BLToolkit.TypeBuilder.Builders | |
6 { | |
7 class FakeParameterInfo : ParameterInfo | |
8 { | |
9 public FakeParameterInfo(string name, Type type, MemberInfo memberInfo, object[] attributes) | |
10 { | |
11 _name = name; | |
12 _type = type; | |
13 _memberInfo = memberInfo; | |
14 _attributes = attributes ?? new object[0]; | |
15 } | |
16 | |
17 public FakeParameterInfo(MethodInfo method) : this( | |
18 "ret", | |
19 method.ReturnType, | |
20 method, | |
21 method.ReturnTypeCustomAttributes.GetCustomAttributes(true)) | |
22 { | |
23 } | |
24 | |
25 public override ParameterAttributes Attributes | |
26 { | |
27 get { return ParameterAttributes.Retval; } | |
28 } | |
29 | |
30 public override object DefaultValue | |
31 { | |
32 get { return DBNull.Value; } | |
33 } | |
34 | |
35 private readonly object[] _attributes; | |
36 | |
37 public override object[] GetCustomAttributes(bool inherit) | |
38 { | |
39 return _attributes; | |
40 } | |
41 | |
42 public override object[] GetCustomAttributes(Type attributeType, bool inherit) | |
43 { | |
44 if (attributeType == null) throw new ArgumentNullException("attributeType"); | |
45 | |
46 if (_attributes.Length == 0) | |
47 return (object[]) Array.CreateInstance(attributeType, 0); | |
48 | |
49 ArrayList list = new ArrayList(); | |
50 | |
51 foreach (object o in _attributes) | |
52 if (o.GetType() == attributeType || attributeType.IsInstanceOfType(o)) | |
53 list.Add(o); | |
54 | |
55 return (object[]) list.ToArray(attributeType); | |
56 } | |
57 | |
58 public override bool IsDefined(Type attributeType, bool inherit) | |
59 { | |
60 if (attributeType == null) throw new ArgumentNullException("attributeType"); | |
61 | |
62 foreach (object o in _attributes) | |
63 if (o.GetType() == attributeType || attributeType.IsInstanceOfType(o)) | |
64 return true; | |
65 | |
66 return false; | |
67 } | |
68 | |
69 private readonly MemberInfo _memberInfo; | |
70 public override MemberInfo Member | |
71 { | |
72 get { return _memberInfo; } | |
73 } | |
74 | |
75 private readonly string _name; | |
76 public override string Name | |
77 { | |
78 get { return _name; } | |
79 } | |
80 | |
81 private readonly Type _type; | |
82 public override Type ParameterType | |
83 { | |
84 get { return _type; } | |
85 } | |
86 | |
87 public override int Position | |
88 { | |
89 get { return 0; } | |
90 } | |
91 } | |
92 } |