26
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
using Mono.Collections.Generic;
29
31
namespace Mono.Cecil {
31
public sealed class ParameterDefinition : ParameterReference, IHasMarshalSpec,
32
IMetadataTokenProvider, ICustomAttributeProvider, IHasConstant {
34
ParameterAttributes m_attributes;
39
MethodReference m_method;
40
CustomAttributeCollection m_customAttrs;
42
MarshalSpec m_marshalDesc;
33
public sealed class ParameterDefinition : ParameterReference, ICustomAttributeProvider, IConstantProvider, IMarshalInfoProvider {
37
internal IMethodSignature method;
39
object constant = Mixin.NotResolved;
40
Collection<CustomAttribute> custom_attributes;
41
MarshalInfo marshal_info;
44
43
public ParameterAttributes Attributes {
45
get { return m_attributes; }
46
set { m_attributes = value; }
44
get { return (ParameterAttributes) attributes; }
45
set { attributes = (ushort) value; }
48
public IMethodSignature Method {
49
get { return method; }
49
52
public bool HasConstant {
50
get { return m_hasConstant; }
56
return constant != Mixin.NoValue;
58
set { if (!value) constant = Mixin.NoValue; }
53
61
public object Constant {
54
get { return m_const; }
62
get { return HasConstant ? constant : null; }
63
set { constant = value; }
61
public MethodReference Method {
62
get { return m_method; }
63
set { m_method = value; }
66
void ResolveConstant ()
68
if (constant != Mixin.NotResolved)
71
this.ResolveConstant (ref constant, parameter_type.Module);
66
74
public bool HasCustomAttributes {
67
get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
70
public CustomAttributeCollection CustomAttributes {
72
if (m_customAttrs == null)
73
m_customAttrs = new CustomAttributeCollection (this);
79
public MarshalSpec MarshalSpec {
80
get { return m_marshalDesc; }
82
m_marshalDesc = value;
84
m_attributes |= ParameterAttributes.HasFieldMarshal;
86
m_attributes &= ~ParameterAttributes.HasFieldMarshal;
76
if (custom_attributes != null)
77
return custom_attributes.Count > 0;
79
return this.GetHasCustomAttributes (parameter_type.Module);
83
public Collection<CustomAttribute> CustomAttributes {
84
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (parameter_type.Module)); }
87
public bool HasMarshalInfo {
89
if (marshal_info != null)
92
return this.GetHasMarshalInfo (parameter_type.Module);
96
public MarshalInfo MarshalInfo {
97
get { return marshal_info ?? (marshal_info = this.GetMarshalInfo (parameter_type.Module)); }
98
set { marshal_info = value; }
90
101
#region ParameterAttributes
92
103
public bool IsIn {
93
get { return (m_attributes & ParameterAttributes.In) != 0; }
96
m_attributes |= ParameterAttributes.In;
98
m_attributes &= ~ParameterAttributes.In;
104
get { return attributes.GetAttributes ((ushort) ParameterAttributes.In); }
105
set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.In, value); }
102
108
public bool IsOut {
103
get { return (m_attributes & ParameterAttributes.Out) != 0; }
106
m_attributes |= ParameterAttributes.Out;
108
m_attributes &= ~ParameterAttributes.Out;
112
public bool IsRetval {
113
get { return (m_attributes & ParameterAttributes.Retval) != 0; }
116
m_attributes |= ParameterAttributes.Retval;
118
m_attributes &= ~ParameterAttributes.Retval;
109
get { return attributes.GetAttributes ((ushort) ParameterAttributes.Out); }
110
set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Out, value); }
122
113
public bool IsLcid {
123
get { return (m_attributes & ParameterAttributes.Lcid) != 0; }
126
m_attributes |= ParameterAttributes.Lcid;
128
m_attributes &= ~ParameterAttributes.Lcid;
114
get { return attributes.GetAttributes ((ushort) ParameterAttributes.Lcid); }
115
set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Lcid, value); }
118
public bool IsReturnValue {
119
get { return attributes.GetAttributes ((ushort) ParameterAttributes.Retval); }
120
set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Retval, value); }
132
123
public bool IsOptional {
133
get { return (m_attributes & ParameterAttributes.Optional) != 0; }
136
m_attributes |= ParameterAttributes.Optional;
138
m_attributes &= ~ParameterAttributes.Optional;
124
get { return attributes.GetAttributes ((ushort) ParameterAttributes.Optional); }
125
set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Optional, value); }
142
128
public bool HasDefault {
143
get { return (m_attributes & ParameterAttributes.HasDefault) != 0; }
146
m_attributes |= ParameterAttributes.HasDefault;
148
m_attributes &= ~ParameterAttributes.HasDefault;
129
get { return attributes.GetAttributes ((ushort) ParameterAttributes.HasDefault); }
130
set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.HasDefault, value); }
133
public bool HasFieldMarshal {
134
get { return attributes.GetAttributes ((ushort) ParameterAttributes.HasFieldMarshal); }
135
set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.HasFieldMarshal, value); }
154
public ParameterDefinition (TypeReference paramType) :
155
this (string.Empty, -1, (ParameterAttributes) 0, paramType)
140
public ParameterDefinition (TypeReference parameterType)
141
: this (string.Empty, ParameterAttributes.None, parameterType)
145
public ParameterDefinition (string name, ParameterAttributes attributes, TypeReference parameterType)
146
: base (name, parameterType)
148
this.attributes = (ushort) attributes;
149
this.token = new MetadataToken (TokenType.Param);
159
152
public override ParameterDefinition Resolve ()
164
public ParameterDefinition (string name, int seq, ParameterAttributes attrs, TypeReference paramType) : base (name, seq, paramType)
166
m_attributes = attrs;
169
public ParameterDefinition Clone ()
171
return Clone (this, new ImportContext (NullReferenceImporter.Instance, m_method));
174
internal static ParameterDefinition Clone (ParameterDefinition param, ImportContext context)
176
ParameterDefinition np = new ParameterDefinition (
180
context.Import (param.ParameterType));
182
if (param.HasConstant)
183
np.Constant = param.Constant;
185
if (param.MarshalSpec != null)
186
np.MarshalSpec = param.MarshalSpec.CloneInto (np);
188
foreach (CustomAttribute ca in param.CustomAttributes)
189
np.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
194
public override void Accept (IReflectionVisitor visitor)
196
visitor.VisitParameterDefinition (this);
198
if (this.MarshalSpec != null)
199
this.MarshalSpec.Accept (visitor);
201
this.CustomAttributes.Accept (visitor);