2 Copyright (C) 2009 Jeroen Frijters
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.
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:
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.
24 using System.Collections.Generic;
26 namespace IKVM.Reflection
28 public abstract class ParameterInfo : ICustomAttributeProvider
30 // prevent external subclasses
31 internal ParameterInfo()
35 public sealed override bool Equals(object obj)
37 ParameterInfo other = obj as ParameterInfo;
38 return other != null && other.Member == this.Member && other.Position == this.Position;
41 public sealed override int GetHashCode()
43 return this.Member.GetHashCode() * 1777 + this.Position;
46 public static bool operator ==(ParameterInfo p1, ParameterInfo p2)
48 return ReferenceEquals(p1, p2) || (!ReferenceEquals(p1, null) && p1.Equals(p2));
51 public static bool operator !=(ParameterInfo p1, ParameterInfo p2)
56 public abstract string Name { get; }
57 public abstract Type ParameterType { get; }
58 public abstract ParameterAttributes Attributes { get; }
59 public abstract int Position { get; }
60 public abstract object RawDefaultValue { get; }
61 public abstract CustomModifiers __GetCustomModifiers();
62 public abstract bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal);
63 public abstract MemberInfo Member { get; }
64 public abstract int MetadataToken { get; }
65 internal abstract Module Module { get; }
67 public Type[] GetOptionalCustomModifiers()
69 return __GetCustomModifiers().GetOptional();
72 public Type[] GetRequiredCustomModifiers()
74 return __GetCustomModifiers().GetRequired();
79 get { return (Attributes & ParameterAttributes.In) != 0; }
84 get { return (Attributes & ParameterAttributes.Out) != 0; }
89 get { return (Attributes & ParameterAttributes.Lcid) != 0; }
94 get { return (Attributes & ParameterAttributes.Retval) != 0; }
97 public bool IsOptional
99 get { return (Attributes & ParameterAttributes.Optional) != 0; }
102 public bool IsDefined(Type attributeType, bool inherit)
104 return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
107 public IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit)
109 return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit);
113 sealed class ParameterInfoWrapper : ParameterInfo
115 private readonly MemberInfo member;
116 private readonly ParameterInfo forward;
118 internal ParameterInfoWrapper(MemberInfo member, ParameterInfo forward)
120 this.member = member;
121 this.forward = forward;
124 public override string Name
126 get { return forward.Name; }
129 public override Type ParameterType
131 get { return forward.ParameterType; }
134 public override ParameterAttributes Attributes
136 get { return forward.Attributes; }
139 public override int Position
141 get { return forward.Position; }
144 public override object RawDefaultValue
146 get { return forward.RawDefaultValue; }
149 public override CustomModifiers __GetCustomModifiers()
151 return forward.__GetCustomModifiers();
154 public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
156 return forward.__TryGetFieldMarshal(out fieldMarshal);
159 public override MemberInfo Member
161 get { return member; }
164 public override int MetadataToken
166 get { return forward.MetadataToken; }
169 internal override Module Module
171 get { return member.Module; }