Merge remote branch 'upstream/master'
[mono.git] / mcs / class / IKVM.Reflection / ParameterInfo.cs
1 /*
2   Copyright (C) 2009 Jeroen Frijters
3
4   This software is provided 'as-is', without any express or implied
5   warranty.  In no event will the authors be held liable for any damages
6   arising from the use of this software.
7
8   Permission is granted to anyone to use this software for any purpose,
9   including commercial applications, and to alter it and redistribute it
10   freely, subject to the following restrictions:
11
12   1. The origin of this software must not be misrepresented; you must not
13      claim that you wrote the original software. If you use this software
14      in a product, an acknowledgment in the product documentation would be
15      appreciated but is not required.
16   2. Altered source versions must be plainly marked as such, and must not be
17      misrepresented as being the original software.
18   3. This notice may not be removed or altered from any source distribution.
19
20   Jeroen Frijters
21   jeroen@frijters.net
22   
23 */
24 using System.Collections.Generic;
25
26 namespace IKVM.Reflection
27 {
28         public abstract class ParameterInfo : ICustomAttributeProvider
29         {
30                 public sealed override bool Equals(object obj)
31                 {
32                         ParameterInfo other = obj as ParameterInfo;
33                         return other != null && other.Member == this.Member && other.Position == this.Position;
34                 }
35
36                 public sealed override int GetHashCode()
37                 {
38                         return this.Member.GetHashCode() * 1777 + this.Position;
39                 }
40
41                 public static bool operator ==(ParameterInfo p1, ParameterInfo p2)
42                 {
43                         return ReferenceEquals(p1, p2) || (!ReferenceEquals(p1, null) && p1.Equals(p2));
44                 }
45
46                 public static bool operator !=(ParameterInfo p1, ParameterInfo p2)
47                 {
48                         return !(p1 == p2);
49                 }
50
51                 public abstract string Name { get; }
52                 public abstract Type ParameterType { get; }
53                 public abstract ParameterAttributes Attributes { get; }
54                 public abstract int Position { get; }
55                 public abstract object RawDefaultValue { get; }
56                 public abstract Type[] GetOptionalCustomModifiers();
57                 public abstract Type[] GetRequiredCustomModifiers();
58                 public abstract MemberInfo Member { get; }
59                 public abstract int MetadataToken { get; }
60                 internal abstract Module Module { get; }
61
62                 public bool IsIn
63                 {
64                         get { return (Attributes & ParameterAttributes.In) != 0; }
65                 }
66
67                 public bool IsOut
68                 {
69                         get { return (Attributes & ParameterAttributes.Out) != 0; }
70                 }
71
72                 public bool IsLcid
73                 {
74                         get { return (Attributes & ParameterAttributes.Lcid) != 0; }
75                 }
76
77                 public bool IsRetval
78                 {
79                         get { return (Attributes & ParameterAttributes.Retval) != 0; }
80                 }
81
82                 public bool IsOptional
83                 {
84                         get { return (Attributes & ParameterAttributes.Optional) != 0; }
85                 }
86
87                 public bool IsDefined(Type attributeType, bool inherit)
88                 {
89                         return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
90                 }
91
92                 public IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit)
93                 {
94                         return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit);
95                 }
96
97                 internal virtual IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
98                 {
99                         return this.Module.GetCustomAttributes(this.MetadataToken, attributeType);
100                 }
101         }
102 }